% % Written by: % -- % John L. Weatherwax 2008-02-20 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- clear all; close all; drawnow; clc; addpath( '../../Code/eda_toolbox' ); randn('seed',0); M=50; x = linspace( 0, +1, M ); % the coeffients for the model: y = beta_1 + beta_2 * x % y = beta_coef(2) + beta_coef(1) * x beta_coef = [ 2, 1 ]; y = polyval( beta_coef, x ); s = 0.15; y = y + s*randn(size(y)); fh=figure; plot( x, y, 'o' ); hold on; % now lets add an outlier to the end of the domain: % indx=M-5; y(indx) = y(indx)*( 1 + 3.2 ); figure(fh); plot( x(indx), y(indx), '-ro', 'MarkerSize', 10, 'MarkerFaceColor', 'r' ); % fit a polynomial model of degree one to this data: % [pcoef,s] = polyfit(x,y,1); fprintf('True model : \n'); fprintf(' y = beta_0 + beta_1 x = %10.6f + %10.6f x\n',beta_coef(2),beta_coef(1)); fprintf('Estimated model : \n'); fprintf(' y = beta_0 + beta_1 x = %10.6f + %10.6f x\n',pcoef(2),pcoef(1)); % plot the true model and the estimated one: % figure(fh); plot( x, polyval(beta_coef,x), '-g' ); figure(fh); plot( x, polyval(pcoef,x), '-r' ); saveas( gcf, ['../../WriteUp/Graphics/Chapter7/prob_7_2'], 'epsc' );