% Eksempel -- Lineaer modell harmonisk svingning

clear all;

x=(0:0.2:4)'; m=21; %antall punkter

y1= ones(m,1)+2.*sin((0.5)*pi*x)-cos((0.5)*pi*x);  

y= y1 + 0.9*(0.5*ones(m,1)-rand(m,1));

figure(13)

plot(x, y,'or')

            %plotter de gitte punktene



X=[ones(m,1) sin((0.5)*pi*x) cos((0.5)*pi*x)]     % X er designmatrisen

beta=X'*X \ X'*y    %gir minste kvadraters losning

t=linspace(-2, 6); 

f= beta(1)+ beta(2)*sin((0.5)*pi*t) + beta(3)*cos((0.5)*pi*t);  %


figure(14)

plot(t,f,'b') 

hold on;

plot(x, y,'or')


