Double Integration Problem Simpson1/3

Hi, So im having a problem with simpson 1/3 for double integration. I dont know if the problem is in the for loop that i created or where. The answer should be pi. Im really stuck on this problem and have been for weeks. If anybody could help I could appreciate it. Here I included the program that im having trouble with.
% For Simpson's 1/3 for double integrals
f=@(x,y) 1; R=1;
a=@(x)-sqrt(R^2-x^2);b=@(x)sqrt(R^2-x^2); % Inner integral bounds
c=-R;d=R; % Outer integral limits
N=600;M=600;
dx=(d-c)/N;
SUM=0;
v = [];
for i = 1:N %loop for Outer
if i == 0 || i == N
k=1;
elseif mod(i,2) ~= 0
k=4;
else
k=2;
end
x = c + i*dx;
v = [v,x];
end
x = sum(v);
dy=(b(x)-a(x))/M;
for j = 1:M %loop for Inner
if j == 0 || j == M
l = 1;
elseif mod(j,2) ~= 0
l = 4;
else
l = 2;
end
y = -sqrt(R^2-x^2) + j*dy;
v = [v,y];
end
y = sum(y);
SUM = SUM + (k*l) * f(x,y); d = (dx/dy)*9; f = (f(a)+f(b)); r = d*SUM;
DS13 = d*SUM + f

1 个评论

Start anew with coding using the composite formula given here:
http://mathfaculty.fullerton.edu/mathews/n2003/SimpsonsRule2DMod.html

请先登录,再进行评论。

回答(0 个)

类别

帮助中心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!

Translated by