Arman Akbarian
UNIVERSITY OF BRITISH COLUMBIA
PHYSICS & ASTRONOMY DEPT.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% AAK:
% Fri Jul 11 15:17:27 PDT 2014
% Example to demonstrate linear fit to multiple functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x=linspace(0,1,10)';
y=0.3 + 1.4*sin(6.1*x)+2.9*cos(4.9*x)+7.1*x;
X=[ones(size(x)) x  sin(6*x) cos(5*x)];
b=X\y
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  b should be 0.3 7.1 1.4 2.9 if the "model", i.e X, 
%  is chosen correctly (6.1 not 6 and 4.9 not 5)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xx=linspace(0,1,1000)';
XX=[ones(size(xx)) xx sin(6*xx) cos(5*xx)];
YY=XX*b;
plot(xx,YY,'-',x,y,'o');


last update: Wed Aug 19, 2015