% % Example on epage 415 % Problem on epage 433 % % 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; clc; addpath('../../Code/CSTool'); load helmets; [stime,inds] = sort(time); saccel = accel(inds); x=stime; y=saccel; fd1=figure; rd=plot( time, accel, '.k' ); hold on; grid on; xlabel( 'time' ); ylabel( 'accel' ); x_sample = linspace( min(time), max(time), 300 ); % Create an inline function to evaluate the weights. mystrg='(2*pi*h^2)^(-1/2)*exp(-0.5*((x - mu)/h).^2)'; wfun = inline(mystrg); % Set up the space to store the estimated values. % We will get the estimate at all values of x. yhatnw = zeros(size(x)); n = length(x); % Set the window width. %h = .1; %h = 1; %h = 1.5; h = 2; %h = 3; % find smooth at each value in x for i = 1:n w = wfun(h,x(i),x); yhatnw(i) = sum(w.*y)/sum(w); end figure(fd1); plot(x,yhatnw,'-x'); title( ['the helmets data with a NW estimator; h=',num2str(h)] ); saveas( gcf, ['../../WriteUp/Graphics/Chapter10/prob_10_15_NW_est'], 'epsc' ); clear functions;