Evaluating a double integral using the trapezoidal rule
이전 댓글 표시
I am trying to take the double integral of the function using the Trapezoidal rule for G=integral (3*x.^2*y+cos(2*x)*sin(y)+2+4*y.^-2*x+5*y)dxdy with x interval 0 to 2pi and y interval 1 to 10. I found a formula for it but don't know the proper syntax to enter it in. We must use the trapezoidal rule because we are comparing different techniques for evaluating integrals. Here is what I have so far:
x1=0;
x2=2*pi;
y1=1;
y2=10;
N=101
dx=(x2-x1)/(N-1);
dy=(y2-y1)/(N-1);
x=x1:dx:x2;
y=y1:dy:y2;
g(x,y)=3*x.^2*y+cos(2*x)*sin(y)+2+4*y.^-2*x+5*y;
N=101;
for i=1:N+1
for j=1:N+1
out(i,j)=((dx*dy)/4)*(g(i,j(1,1))+g(i,j(1,N))+g(i,j(N,1))+g(i,j(N,N))+2*(g(i,j(1,2:1:N-1))+g(i,j(N,2:1:N-1))+g(i,j(2:1:N-1,1))+g(i,j(2:1:N-1,N)))+4*(sum(g(i,j(2:1:N-1,2:1:N-1)))));
end
end
The really long formula is from this source: http://www.math.ohiou.edu/courses/math344/lecture24.pdf on page 2. I feel that I could streamline the code by using more summation but I do not know how to do that.
채택된 답변
추가 답변 (2개)
Mohammed
2023년 12월 12일
0 개 추천
∫ 𝑠𝑖𝑛𝑥𝑑𝑥 𝜋 0 = 𝑐𝑜𝑠
카테고리
도움말 센터 및 File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!