
function dahlquist56

k=0:3;
Nk=2.^k*10;

[x,y,errs]=dahl_example(Nk(1));
semilogy(x,errs,'cd-');

hold on

[x,y,errs]=dahl_example(Nk(2));
semilogy(x,errs,'rd-');

[x,y,errs]=dahl_example(Nk(3));
semilogy(x,errs,'yd-');

[x,y,errs]=dahl_example(Nk(4));
semilogy(x,errs,'gd-');

legend('10','20','40','80')

hold off


function [x,y,errs]=dahl_example(N)

x=linspace(0,1,N+1);
y=[1 exp(x(2))];
h=1/N;

for n=2:N
    y(n+1)=-4*y(n)+5*y(n-1)+h*(4*y(n)+2*y(n-1));
end

errs=abs(exp(x)-y);