function crank_nicolson_stability h=10; t=0:h:100; [l,m]=size(t); x(1)=1; for i=2:m; x(i)=(1-h/2)/(1+h/2)*x(i-1); end M=max(abs(x)); if (M>1) M=10; Mi=-10; else Mi=-1; M=1; end y=exp(-t); figure(1) plot(t,y,'r',t,x,'b') title('crank-nicolson method') axis([0 100 Mi M])