Composite Trapezoid rule
Mostrar comentarios más antiguos
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 comentarios
bym
el 9 de Abr. de 2011
are you sure the answer is 2?
Walter Roberson
el 9 de Abr. de 2011
I'm not sure what n is supposed to be here. If it is the number of subdivisions to take, then perhaps the trapezoid comes out as 2 ?
Jason
el 10 de Abr. de 2011
Walter Roberson
el 10 de Abr. de 2011
Are you remembering to multiply by the width of the interval ?
John D'Errico
el 10 de Abr. de 2011
Well, in this case, the width of the interval is exactly 1, so I'm guessing the error is in another place.
John D'Errico
el 10 de Abr. de 2011
To Jason - why not show what you have tried? You are far more likely to get help that way. I'll give you one hint. Did you start with meshgrid?
John D'Errico
el 10 de Abr. de 2011
or ndgrid?
Jason
el 10 de Abr. de 2011
bym
el 10 de Abr. de 2011
I don't see where n factors into your equations. I would suggest you look at meshgrid like John suggested
Jason
el 10 de Abr. de 2011
Jason
el 10 de Abr. de 2011
Jason
el 10 de Abr. de 2011
bym
el 10 de Abr. de 2011
why can't you use meshgrid? Is it specifically forbidden or you don't understand how to use it?
Jason
el 10 de Abr. de 2011
John D'Errico
el 11 de Abr. de 2011
Suppose you knew the value of this function, (x^2-2y^2+xy^3) at a grid of points. Would that help you?
Jason
el 11 de Abr. de 2011
bym
el 11 de Abr. de 2011
how would you plot such a function?
Jason
el 11 de Abr. de 2011
Jason
el 11 de Abr. de 2011
John D'Errico
el 11 de Abr. de 2011
We are not going to do your homework for you. I'm sorry that you have other things to do with your time, but if doing your homework is important to you, then you will find the time. And if it is not important to you, then why should we spend the time to do something that is not important to you anyway? There have been MANY hints offered to you.
Jiro Doke
el 11 de Abr. de 2011
To save you time, I will say that I'm not aware of any built in MATLAB function like cumtrapz for 2D. So your best bet is to implement the algorithm yourself (kind of like the way you did in one of your comments).
The command meshgrid (or ndgrid) helps you easily set up the "grid points" that you need for your algorithm. For example, notice that you went and calculated all the points based on the x and y limits and n. You could do that with meshgrid this way:
[x, y] = meshgrid(linspace(ax, bx, n+1), linspace(ay, by, n+1))
Once you have those, then it's just a matter of using those with your function "(x^2-2y^2+xy^3)" in the composite trapezoidal rule.
Jason
el 11 de Abr. de 2011
Jason
el 11 de Abr. de 2011
Respuestas (1)
Sulaymon Eshkabilov
el 11 de Sept. de 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);
Categorías
Más información sobre Numerical Integration and Differentiation en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!