% Adams
%
% This script is part of the material of the lecture
%   Theory and Numerics of Ordinary Differential Equations
% at the Math Department of Halle University, Germany.
% Winter term 2008/09
%
% Author :      Prof. Dr. M. Arnold, arnold@mathematik.uni-halle.de
% Version of :  Nov 17, 2004
%
% Explicit and implicit Adams methods applied to y´(x) = y, (x\in[0,1]), y(0) = 1

% Adams explicit, k=1, M=3, h=1/3
%             0  1.0000e+000            0
%   3.3333e-001  1.3333e+000 -6.2279e-002
%   6.6667e-001  1.7778e+000 -1.6996e-001
%   1.0000e+000  2.3704e+000 -3.4791e-001
M=3;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1)=1;
for m=1:M, y(1+m)=y(m)+h*y(m);end;[x,y,y-exp(x)]

% Adams explicit, k=1, M=6, h=1/6
%   1.0000e+000  2.5216e+000 -1.9666e-001
M=6;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1)=1;
for m=1:M, y(1+m)=y(m)+h*y(m);end;[x,y,y-exp(x)]

% Adams explicit, k=1, M=12, h=1/12
%   1.0000e+000  2.6130e+000 -1.0525e-001
M=12;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1)=1;
for m=1:M, y(1+m)=y(m)+h*y(m);end;[x,y,y-exp(x)]

% Adams explicit, k=1, M=24, h=1/24
%   1.0000e+000  2.6637e+000 -5.4551e-002
M=24;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1)=1;
for m=1:M, y(1+m)=y(m)+h*y(m);end;[x,y,y-exp(x)]

% Adams explicit, k=2, M=3, h=1/3
%             0  1.0000e+000            0
%   3.3333e-001  1.3956e+000            0
%   6.6667e-001  1.9268e+000 -2.0982e-002
%   1.0000e+000  2.6575e+000 -6.0756e-002
k=2;M=3;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1:k)=exp(x(1:k));
for m=k:M, y(1+m)=y(m)+h/2*(3*y(m)-y(m-1));end;[x,y,y-exp(x)]

% Adams explicit, k=2, M=6, h=1/6
%   1.0000e+000  2.6954e+000 -2.2883e-002
k=2;M=6;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1:k)=exp(x(1:k));
for m=k:M, y(1+m)=y(m)+h/2*(3*y(m)-y(m-1));end;[x,y,y-exp(x)]

% Adams explicit, k=2, M=12, h=1/12
%   1.0000e+000  2.7115e+000 -6.7917e-003
k=2;M=12;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1:k)=exp(x(1:k));
for m=k:M, y(1+m)=y(m)+h/2*(3*y(m)-y(m-1));end;[x,y,y-exp(x)]

% Adams explicit, k=2, M=24, h=1/24
%   1.0000e+000  2.7164e+000 -1.8332e-003
k=2;M=24;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1:k)=exp(x(1:k));
for m=k:M, y(1+m)=y(m)+h/2*(3*y(m)-y(m-1));end;[x,y,y-exp(x)]

% Adams explicit, k=3, M=3, h=1/3
%             0  1.0000e+000            0
%   3.3333e-001  1.3956e+000            0
%   6.6667e-001  1.9477e+000            0
%   1.0000e+000  2.7107e+000 -7.5455e-003
k=3;M=3;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1:k)=exp(x(1:k));
for m=k:M, y(1+m)=y(m)+h/12*(23*y(m)-16*y(m-1)+5*y(m-2));end;[x,y,y-exp(x)]

% Adams explicit, k=3, M=6, h=1/6
%   1.0000e+000  2.7157e+000 -2.6018e-003
k=3;M=6;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1:k)=exp(x(1:k));
for m=k:M, y(1+m)=y(m)+h/12*(23*y(m)-16*y(m-1)+5*y(m-2));end;[x,y,y-exp(x)]

% Adams explicit, k=3, M=12, h=1/12
%   1.0000e+000  2.7178e+000 -4.4894e-004
k=3;M=12;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1:k)=exp(x(1:k));
for m=k:M, y(1+m)=y(m)+h/12*(23*y(m)-16*y(m-1)+5*y(m-2));end;[x,y,y-exp(x)]

% Adams explicit, k=3, M=24, h=1/24
%   1.0000e+000  2.7182e+000 -6.4631e-005
k=3;M=24;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1:k)=exp(x(1:k));
for m=k:M, y(1+m)=y(m)+h/12*(23*y(m)-16*y(m-1)+5*y(m-2));end;[x,y,y-exp(x)]

% Adams implicit, k=1, M=3, h=1/3
%             0  1.0000e+000            0
%   3.3333e-001  1.3889e+000 -6.7235e-003
%   6.6667e-001  1.9290e+000 -1.8722e-002
%   1.0000e+000  2.6792e+000 -3.9098e-002
k=1;M=3;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1:k)=exp(x(1:k));
for m=k:M, ye=y(m)+h*y(m);y(1+m)=y(m)+h/2*(y(m)+ye);end;[x,y,y-exp(x)]

% Adams implicit, k=1, M=6, h=1/6
%   1.0000e+000  2.7072e+000 -1.1093e-002
k=1;M=6;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1:k)=exp(x(1:k));
for m=k:M, ye=y(m)+h*y(m);y(1+m)=y(m)+h/2*(y(m)+ye);end;[x,y,y-exp(x)]

% Adams implicit, k=1, M=12, h=1/12
%   1.0000e+000  2.7153e+000 -2.9545e-003
k=1;M=12;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1:k)=exp(x(1:k));
for m=k:M, ye=y(m)+h*y(m);y(1+m)=y(m)+h/2*(y(m)+ye);end;[x,y,y-exp(x)]

% Adams implicit, k=1, M=24, h=1/24
%   1.0000e+000  2.7175e+000 -7.6226e-004
k=1;M=24;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1:k)=exp(x(1:k));
for m=k:M, ye=y(m)+h*y(m);y(1+m)=y(m)+h/2*(y(m)+ye);end;[x,y,y-exp(x)]

% Adams implicit, k=2, M=3, h=1/3
%             0  1.0000e+000            0
%   3.3333e-001  1.3956e+000            0
%   6.6667e-001  1.9456e+000 -2.1589e-003
%   1.0000e+000  2.7122e+000 -6.1013e-003
k=2;M=3;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1:k)=exp(x(1:k));
for m=k:M, ye=y(m)+h/2*(3*y(m)-y(m-1));y(1+m)=y(m)+h/12*(5*ye+8*y(m)-y(m-1));end;[x,y,y-exp(x)]

% Adams implicit, k=2, M=6, h=1/6
%   1.0000e+000  2.7171e+000 -1.1524e-003
k=2;M=6;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1:k)=exp(x(1:k));
for m=k:M, ye=y(m)+h/2*(3*y(m)-y(m-1));y(1+m)=y(m)+h/12*(5*ye+8*y(m)-y(m-1));end;[x,y,y-exp(x)]

% Adams implicit, k=2, M=12, h=1/12
%   1.0000e+000  2.7181e+000 -1.7372e-004
k=2;M=12;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1:k)=exp(x(1:k));
for m=k:M, ye=y(m)+h/2*(3*y(m)-y(m-1));y(1+m)=y(m)+h/12*(5*ye+8*y(m)-y(m-1));end;[x,y,y-exp(x)]

% Adams implicit, k=2, M=24, h=1/24
%   1.0000e+000  2.7183e+000 -2.3760e-005
k=2;M=24;y=zeros(M+1,1);h=1/M;x=linspace(0,1,M+1)';y(1:k)=exp(x(1:k));
for m=k:M, ye=y(m)+h/2*(3*y(m)-y(m-1));y(1+m)=y(m)+h/12*(5*ye+8*y(m)-y(m-1));end;[x,y,y-exp(x)]
