%Generate the x values: x=0:.25:10; x2=0:.01:10; %generate normal errors for the x values. err=.25*randn(1,length(x)); %Find the mean function for the data z=sin(2*x).*exp(-.2.*x); %Simulate the observed data by adding noise y=z+err; z=sin(2*x2).*exp(-.2.*x2); %plot the real function plot(x2,z,'k-') hold on plot(x,y,'bo') hold off %There are 41 values for x, so we can fit a 40 order polynomial to the %data. polFit=polyfit(x,y,40); %Then find the values of the fit over the values of: y_poly=polyval(polFit,x2); %Then the fit onto the plot plot(x2,z,'k-') hold on plot(x,y,'r.') plot(x2,y_poly,'b-') hold off; %Open our data set U = load('data1'); t = U.trace_x'; disp = U.trace_y(4,:); N = length(t); time = t; [maxd,index] = max(disp); % do some truncation to eliminate the data before the maximum time = time(index:N)-time(index); disp = disp(index:N); disp = disp'; disp = disp - mean(disp); d_data = disp; plot(time, disp,'b.'); xlabel('t'); ylabel('y(t)'); polFit=polyfit(time,disp,150); %Then find the values of the fit over the values of: y_poly=polyval(polFit,time); %Then the fit onto the plot plot(time,disp,'k.',time,y_poly,'b-'); xlabel('t'); ylabel('y(t)');