Composite Trapezoid rule

36 views (last 30 days)
Jason
Jason on 9 Apr 2011
I know for a single integral you would use the cumtrapz function. I have a problem where I have to use the composite trapz rule on a double integral and I can find nothing on how to do that. The function is
(x^2 - 2y^2 +xy^3)dxdy where the outer y limits are -1:1 the inner x limits are 0:2 and n = 2
Any help would be much appreciated. The answer is supposed to be 2.
  23 Comments
Jason
Jason on 11 Apr 2011
Jiro, I really appreciate that. I finally found somewhat similar application of the com trapz rule that I was able to use to figure it out. I was close originally and it was just missing a simple step. I have never used meshgrid, nor has it been discussed in class to this point so I would never have thought of using it nor would I know how to. Thank you for taking a moment to explain it. I already have the problem figured out but the meshgrid information will be useful in the future.
Jason
Jason on 11 Apr 2011
To clarify the missing part of what I had was to divide the entire B expression by 2n, which in this case would be 4. It's just too obvious, but looking at the basic form of the composite trapezoidal rule clearly shows it. Thanks again for the help even though it was something simple I missed.

Sign in to comment.

Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 11 Sep 2020
Here is a simple solution to this exercise:
x = -1:0.02:1;
y = -1:0.025:1;
[xx,yy] = meshgrid(x,y);
Fun = xx.^2 -2*yy.^2+xx.*yy.^2;
ALL = cumtrapz(y,cumtrapz(x,Fun,2));
mesh(xx,yy,Fun)
xlabel('x')
ylabel('y')
str = '$$ \int_{-1}^{1} \int_{-1}^{1} (x^2 -2*y^2+x*y^2 )dxdy $$';
zlabel(str,'Interpreter','latex')
hold on
surf(xx,yy,ALL,'FaceAlpha',0.5,'EdgeColor','none')
plot3(xx(end),yy(end),ALL(end),'md', 'markerfacecolor', 'c')
v = [1 1 1];
view(v);

Products

Community Treasure Hunt

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

Start Hunting!