二阶 Adams 方法的 MATLAB 程序代码
format long
N=20;
M = [5 10 20 40 80];
for m=M
h=1/m;
t=0 : h : N;
x=t;
x(1)=1/2;
k=2;
for i=2:k
x(i)=exp(t(i))/(1+exp(t(i)));
end
for i=k:m*N
x(i+1)=x(i)+h*(3/2)*x(i)*(1-x(i))-(1/2)*h*x(i-1)*(1-x(i-1));
if mod(i+1,2*m)==1,
x(i+1)=x(i+1)+(1-exp(2))/(2*(1+exp(2)));
end
end
error=(x(m*N+1)-(1-exp(2))/(2*(1+exp(2)))-exp(2)/(1+exp(2))),
%rerror=(x(m*N+1)-(1-exp(2))/(2*(1+exp(2)))-
exp(2)/(1+exp(2)))/(exp(2)/(1+exp(2))),
end
plot(t , x);
hold on
四阶 Adams 方法的 MATLAB 程序代码
format long
N=20;
M=[5 10 20 40 80];