Composite Trapezoid rule
이전 댓글 표시
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
bym
2011년 4월 9일
are you sure the answer is 2?
Walter Roberson
2011년 4월 9일
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
2011년 4월 10일
Walter Roberson
2011년 4월 10일
Are you remembering to multiply by the width of the interval ?
John D'Errico
2011년 4월 10일
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
2011년 4월 10일
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
2011년 4월 10일
or ndgrid?
Jason
2011년 4월 10일
bym
2011년 4월 10일
I don't see where n factors into your equations. I would suggest you look at meshgrid like John suggested
Jason
2011년 4월 10일
Jason
2011년 4월 10일
Jason
2011년 4월 10일
bym
2011년 4월 10일
why can't you use meshgrid? Is it specifically forbidden or you don't understand how to use it?
Jason
2011년 4월 10일
John D'Errico
2011년 4월 11일
Suppose you knew the value of this function, (x^2-2y^2+xy^3) at a grid of points. Would that help you?
Jason
2011년 4월 11일
bym
2011년 4월 11일
how would you plot such a function?
Jason
2011년 4월 11일
Jason
2011년 4월 11일
John D'Errico
2011년 4월 11일
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
2011년 4월 11일
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
2011년 4월 11일
Jason
2011년 4월 11일
답변 (1개)
Sulaymon Eshkabilov
2020년 9월 11일
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);
카테고리
도움말 센터 및 File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!