% demo: integrate x'(t) = x(t), x(0)=1 % Stability example, part 2 (unstable method) f = inline('x','t','x'); h = input('step size, h: ') x = [1; exp(h)]; % begin with exact values for x0, x1 steps = ceil(1.25/h); for k=1:steps-1 x(k+2) = 3*x(k+1)-2*x(k)+h*(.5*f((k+1)*h,x(k+1)) + (-1.5)*f(k*h,x(k))); end figure(1), clf t = linspace(0,steps*h,500); plot(t, exp(t), 'b-', 'linewidth', 2), hold on plot([0:h:steps*h], x, 'r-','linewidth',2) plot([0:h:steps*h], x, 'r.','markersize',20) axis([0 1.25 0 3.5]) set(gca,'fontsize',16) legend('exact', 'method 2',2)