STANAANDREY

periodic least square meth

Mar 27th, 2023
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.34 KB | None | 0 0
  1. t=0:1/8:7/8;
  2. y=[-2.2 -2.8 -6.1 -3.9 0 1.1 -0.6 -1.1]';
  3. CCoef = @(t)[1 cos(2*pi*t) sin(2*pi*t)];
  4. m = length(t);
  5. n = length(CCoef(NaN));
  6. A=zeros(m, n);
  7. for i=1:m
  8.     A(i,:) = CCoef(t(i));
  9. end
  10. %lsm
  11. ATA = A'*A;
  12. ATB=A'*y;
  13. c = ATA\ATB;
  14. predfn=@(t)c(1)+c(2)*cos(2*pi*t)+c(3)*sin(2*pi*t);
  15. fplot(predfn, [0 1], 'red')
  16. hold on
  17. plot(t, y', '*')
  18.  
Add Comment
Please, Sign In to add comment