% % 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. % %----- % EPage 136 close all; clc; clear; xs = [ -2, 0, 2, 3, 4, 5 ]; ys = [ 4, 0, -4, -30, -40, -50 ]; plot( xs, ys, '.k', 'MarkerSize', 18 ); hold('on'); grid('on'); xx = linspace( min(xs), max(xs), 50 ); % Fit a spline to this data: % pp = spline( xs, ys ); ys_spline = ppval( pp, xx ); plot( xx, ys_spline, '-b' ); % Fit a fith degree polynomial to this data: % poly_coefs = polyfit( xs, ys, 5 ); ys_poly = polyval( poly_coefs, xx ); plot( xx, ys_poly, '-r' ); legend( 'truth', 'spline', 'fifth degree polynomial', 'location', 'best' ); %saveas( gcf, '../../WriteUp/Graphics/Chapter7/c_7_p_5_plot.eps', 'epsc' );