non continuous double integration

2 views (last 30 days)
Ahmed Abdulla on 6 Jun 2021
Answered: John D'Errico on 6 Jun 2021
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
Ahmed Abdulla on 6 Jun 2021
Thank you for your time, sorry I am not very sure how to word it.
To apply the trapezoidal rule, should i evaluate the integrated function at each set of points then sum up the findings?

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)
x = 4×4
20 33 47 85 20 33 47 85 20 33 47 85 20 33 47 85
y = 4×4
10 10 10 10 22 22 22 22 43 43 43 43 98 98 98 98
z = Zfun(x,y)
z = 4×4
10000 39237 108523 622625 17680 51909 126571 655265 44980 96954 190726 771290 200080 352869 555211 1430465
intest = trapz(Xnodes,trapz(Ynodes,z,1),2)
intest = 2.4820e+09
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)
ans =
2214362150
So the trapezoidal estimate was within 10% of the exact value. Probably as good as we could do on that set of nodes.

Categories

Find more on Numerical Integration and Differentiation in Help Center and File Exchange

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!