% % 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'); % Problem 5.1: fh = figure; subplot(1,2,1); y0 = 50; global k; k = 0.05; y_truth = @(t) ( y0*exp(-k*t) ); [tvals, yvals] = fhermite( @(t,x) c_5_p_1_f_n_fp(t,x), [0,10], y0, 1 ); yvals(end) plot( tvals, yvals, '-r' ); hold('on'); plot( tvals, y_truth(tvals), '-g' ); xlabel('t'); ylabel('y(t) for 5.1'); % Problem 5.2: subplot(1,2,2); y0 = 2; y_truth = @(t) ( 2*exp(t.^2) ); [tvals, yvals] = fhermite( @(t,x) c_5_p_2_f_n_fp(t,x), [0,2], y0, 0.2 ); yvals(end) plot( tvals, yvals, '-.r' ); hold('on'); [tvals, yvals] = fhermite( @(t,x) c_5_p_2_f_n_fp(t,x), [0,2], y0, 0.02 ); yvals(end) plot( tvals, yvals, '.k' ); plot( tvals, y_truth(tvals), '-g' ); xlabel('t'); ylabel('y(t) for 5.2'); axis tight; %saveas( gcf, '../../WriteUp/Graphics/Chapter5/c_5_p_5_plot.eps', 'epsc' );