function err = myfitfun(d,x,y,handle)
%FITFUN Used by FITDEMO.
%   FITFUN(lambda,t,y,handle) returns the error between the data and the values
%   computed by the current function of lambda.
% 
%    modified by VdS from
%   Copyright 1984-2002 The MathWorks, Inc. 
%   $Revision: 5.8 $  $Date: 2002/04/15 03:36:42 $

  %  remember we are fitting y=ax + bx^2 + ce^(-dx) +e 
  % for given parameter d set up the problem to solve for the a,b,c and e using our 
  % linear regression method
  % given d we can solve for a,b,c and e using our linear regression method
A = [x x.^2   exp(-d*x) ones(length(x),1)];
abce = A\y

  % compute the values at the given x points for the found a,b,c,e and given d
z = A*abce;
  % compute the error from the given y points
err = norm(z-y);

set(gcf,'DoubleBuffer','on');
set(handle,'ydata',z)
drawnow
pause(.04)
