home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 3.ddi / DEMOS.DI$ / FITFUN.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  622 b   |  26 lines

  1. function err = fitfun(lambda)
  2. %FITFUN Used by FITDEMO.
  3. %    FITFUN(lambda) returns the error between the data and the
  4. %    values computed by the current function of lambda.
  5. %    FITFUN assumes a function of the form
  6. %
  7. %      y =  c(1)*exp(-lambda(1)*t) + ... + c(n)*exp(-lambda(n)*t)
  8. %
  9. %    with n linear parameters and n nonlinear parameters.
  10.  
  11. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  12.  
  13. global Data Plothandle
  14.  
  15. t = Data(:,1);
  16. y = Data(:,2);
  17. A = zeros(length(t),length(lambda));
  18. for j = 1:size(lambda)
  19.    A(:,j) = exp(-lambda(j)*t);
  20. end
  21. c = A\y;
  22. z = A*c;
  23. set(Plothandle,'ydata',z)
  24. drawnow
  25. err = norm(z-y);
  26.