% % Written by: % -- % John L. Weatherwax 2009-04-21 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- close all; clc; clear all; addpath('../../BookCode'); h = 2; y0 = 50; k = 0.05; y_truth = @(t) ( y0*exp(-k*t) ); fprime = @(t,y) ( -k * y ); [tvals, yvals] = abm( fprime, [0,50], y0, h ); v_1 = yvals(end); relative_error = ( yvals - y_truth(tvals) ) ./ y_truth(tvals); ph_abm = plot( tvals, relative_error, '-r' ); hold('on'); [tvals, yvals] = fhamming( fprime, [0,50], y0, h ); v_2 = yvals(end); relative_error = ( yvals - y_truth(tvals) ) ./ y_truth(tvals); ph_hamming = plot( tvals, relative_error, '-k' ); [ v_1, v_2, y_truth(50) ] legend( [ph_abm,ph_hamming], 'ABM h=2', 'Hamming h=2', 'location', 'southwest' ); xlabel('time'); ylabel('y(t)'); grid('on'); %saveas( gcf, '../../WriteUp/Graphics/Chapter5/c_5_p_3_plot.eps', 'epsc' );