home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 4.ddi / OPTIM.DI$ / FITFUN2.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  851 b   |  27 lines

  1. function f = fitfun2(lam,Data)
  2. %FITFUN2  Used  by DATDEMO to return errors in fitting data to a function.
  3. %    FITFUN2 is used by DATDEMO.  FITFUN2(lam,Data) returns the error
  4. %    between the data and the values computed by the current
  5. %    function of lam.  FITFUN2 assumes a function of the form
  6. %
  7. %      y =  c(1)*exp(-lam(1)*t) + ... + c(n)*exp(-lam(n)*t)
  8. %
  9. %    with n linear parameters and n nonlinear parameters.
  10.  
  11. t = Data(:,1); y = Data(:,2);
  12. A = zeros(length(t),length(lam));
  13. for j = 1:size(lam)
  14.    A(:,j) = exp(-lam(j)*t);
  15. end
  16. c = A\y;
  17. z = A*c;
  18. f = z-y;
  19.  
  20. % Statements to plot progress of fitting:
  21. plot(t,z,t,y,'o')
  22. xt = max(t)/3;
  23. yt = max(y)/2;
  24. text(xt,1.4*yt,['lambda = ' num2str(lam(1)) '  ' num2str(lam(2))])
  25. text(xt,1.2*yt,['(c = ' num2str(c(1)) '  ' num2str(c(2)),')'])
  26. text(xt,1.0*yt,['err norm = ' sprintf('%g',norm(f))])
  27.