load 'unemployment.data'; Y=unemployment(:,3); t=[1:252]' X=[ones(252,1),cos(pi*t/6),cos(2*pi*t/6)] >>a=inv(X'*X)*X'*Y a = 6.6913 0.0181 0.0258 >>mean(Y) ans = 6.6913 plot(t,Y); mu=6.6913 + 0.0181*cos(pi*t/6) + 0.0258*cos(2*pi*t/6); hold plot(t,mu,'-') X=[ones(252,1),cos(0.1047*t),cos(2*0.1047*t)] >>a=inv(X'*X)*X'*Y a = 6.7060 -0.4324 0.0252 plot(t,Y); mu=6.7060 - 0.4324*cos(0.1047*t) + 0.0252*cos(2*0.1047*t); hold plot(t,mu,'-') %We need to increase the smoothness >> 2*pi/252 ans = 0.0249 X=[ones(252,1),cos(0.0249*t),cos(2*0.0249*t),cos(3*0.0249*t)] >> a=inv(X'*X)*X'*Y a = 6.6898 -1.2512 -0.5112 0.6323 plot(t,Y); mu=6.6898 - 1.2512*cos(0.0249*t) - 0.5112*cos(2*0.0249*t) + 0.6323*cos(3*0.0249*t); hold plot(t,mu,'-')