此代码展示了Euler计算方法与差分方法
源代码在线查看: ep2_p1.m
% Ep2_p1: > 数值积分 算式(2.8)
% Designed by FGH
% m= 4;
a= 30.6;
b= 29.6;
R= 30;
h= 1/m;
k= 2*pi/m;
e= 0 : k : 2*pi;
t= (0 : h : 1)';
% 算式(2.13)
f= sqrt(t.^2*ones(size(t))' + R^2*(1-t.^2)*((cos(e)/a).^2+(sin(e)/b).^2));
% 与上式等价的程序
% for j= 1:m+1
% for i= 1:m+1
% f(i,j)= sqrt(t(j)^2+R^2*(1-t(j)^2)*((cos(e(i))/a)^2+(sin(e(i))/b)^2));
% end
% end
clear Iij;
for j= 2:m+1
for i= 2:m+1
% 算式(2.8)
Iij(i,j)= k*h/4*( f(i-1,j-1)+f(i,j-1)+f(i-1,j)+f(i,j) );
end
end
I= sum(sum(Iij));
S= a*b*I;
sprintf(' m = %d , S = %7.2f\n',m,S)