Double integral of numerical data
22 views (last 30 days)
Show older comments
Kushal Chode
on 29 May 2019
Commented: Star Strider
on 16 Dec 2023
Hi,
Thank you for viewing the question,
I want to perform double intergal of numerical data I have. It represents pressure at every point and the data is imported as column vectors, x, y (respresenting area in 2D) and P. I have to get the force, as force is given as double_intergal (p(x,y)). Trapz is a option available in Matlb to perform intergation on numerical data, how can I use trapz as double integral? and is there any method alternate to trapz which I can use.
Thank you
Cheers
KC
0 Comments
Accepted Answer
Star Strider
on 29 May 2019
‘... how can I use trapz as double integral?’
If your x, y, and P vectors represent an area in 2D, they may be gridded. You would first need to use the reshape function to get them into matrices (this is not difficult), then use trapz on each dimension:
P = rand(5,6); % Create ‘P’ Matrix
I1 = trapz(P) % First Integration
Result = trapz(I1) % Second Integration
10 Comments
Pankaj
on 16 Dec 2023
Edited: Pankaj
on 16 Dec 2023
@Star Strider Thanks for the detailed ans.I have a question, lets say I have a three column data set x, y, p(x,y) and the data is such that for each value of x, there is 100 values of y , so basically the first column values are repeating 100 times for 100 values of y and for each pair of x,y there is a p(x,y) present. And there are 200 unique x and 100 unique y. How to get the double integration of p(x,y) in that case ?
Star Strider
on 16 Dec 2023
I get the impression that the data are gridded. If so, you first need to reshape them all to matrices, then choose the appropriate row or column of each ‘x’ and ‘y’ matrix that increment (rather than being constant), and use that and the matching dimension of ‘p’ to do each integration.
That would go something like this —
x = [1;2;3;1;2;3;1;2;3];
y = [1;1;1;2;2;2;3;3;3];
p = randn(9,1);
xr = reshape(x, 3, [])
yr = reshape(y, 3, [])
pr = reshape(p, 3, [])
int2 = trapz(xr(:,1), pr, 2)
intp = trapz(yr(1,:), int2)
.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!