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!