reverse-shooting

Matlab scripts for reverse shooting
Log | Files | Refs | README

fitpoly.m (315B)


      1 %  FITPOLY.m
      2 %
      3 % function [yfit beta]=fitpoly(y,n);
      4 %
      5 %  Returns the best-fitting nTH order polynomial that first the series y
      6 %  using least squares.  beta contains the OLS coefficients.
      7 
      8 function [yfit,beta]=fitpoly(y,n);
      9 
     10 T=length(y);
     11 t=(1:T)';
     12 X=[];
     13 for i=0:n;
     14    X=[X t.^i];
     15 end;
     16 beta=lstiny(y,X);
     17 yfit=X*beta;