Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- t=0:1/8:7/8;
- y=[-2.2 -2.8 -6.1 -3.9 0 1.1 -0.6 -1.1]';
- CCoef = @(t)[1 cos(2*pi*t) sin(2*pi*t)];
- m = length(t);
- n = length(CCoef(NaN));
- A=zeros(m, n);
- for i=1:m
- A(i,:) = CCoef(t(i));
- end
- %lsm
- ATA = A'*A;
- ATB=A'*y;
- c = ATA\ATB;
- predfn=@(t)c(1)+c(2)*cos(2*pi*t)+c(3)*sin(2*pi*t);
- fplot(predfn, [0 1], 'red')
- hold on
- plot(t, y', '*')
Add Comment
Please, Sign In to add comment