non continuous double integration
1 view (last 30 days)
Show older comments
I am looking to integrate the following function 5sin(x) dx dy, however I am only aware of performing integrals for specific upper bounds using integral2.
Does anyone know if it is possible/how to perform this double integration given x and y are non continuous set of numbers. x and y, x=[20 33 47 85] and y=[10 22 43 98].
*Sorry if the title isn't clear
Accepted Answer
John D'Errico
on 6 Jun 2021
Ok, now that we understand the question, it is easy. Just use trapz, TWICE.
To apply the trapezoidal rule, you will create a matrix of 4x4 elements. Then call trapz twice, once on each dimension of the array. I won't do your problem here, since this seems too much likely to be homework.
But for example, suppose I wanted to integrate the function
z = x.^3 + x.*y^2
over the domain (x,y) = [20,85] X [10,98], where we will sample the function at that set of nodes? This is VERY different from what you wanted to call a discontinuous point set of some sort.
Zfun = @(X,Y) X.^3 + X.*Y.^2;
Xnodes = [20 33 47 85];
Ynodes = [10 22 43 98];
[x,y] = meshgrid(Xnodes,Ynodes)
z = Zfun(x,y)
intest = trapz(Xnodes,trapz(Ynodes,z,1),2)
How accurate is that estimate? Remember, this is just trapezoidal integration, over a VERY coarse set of nodes.
syms X Y
int(int(X.^3 + X.*Y.^2,X,20,85),Y,10,98)
So the trapezoidal estimate was within 10% of the exact value. Probably as good as we could do on that set of nodes.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!