% BRIEF RECAP of October 1st, 1998 NEEP271 lecture
% written by Fabian Waleffe 98/10/02
%
% we went through how to store and plot data in Matlab again.
% Reviewed "storeandplot.m" which has been posted on the 
% web page and e-mailed to all properly registered students
% earlier this week
%
% Lecture objective: learn about "polyfit", "polyval" and 
% review the ideas behind them.
% BEST FIT IN A LEAST-SQUARES SENSE 
% you are supposed to understand that concept.
% what does "best fit in a least-squares sense" mean?
% can you FORMULATE the problem? 
%
% TRY THIS OUT FOR YOURSELF!! 
% MAKE SURE YOU UNDERSTAND EACH LINE, TRY VARIATIONS, ETC..

clear
help clear

x=[1:0.1:10];  size(x)
x=x';           size(x)

y=2*x+3;

colordef none
help colordef

plot(x,y,'-*')
help plot

yr=y+rand(length(y),1).*x;
help ops
help times
size(x'*x), size(x*x'), size(x.*x)

plot(x,y,x,yr,':x')
help rand

help polyfit
help polyval
p=polyfit(x,yr,1)
plot(x,y,x,yr,':x',x,polyval(p,x))

p5=polyfit(x,yr,5)
plot(x,y,x,yr,':x',x,polyval(p,x),x,polyval(p5,x))

