function err = fitfuntx(lambda,t,y,handle)
%FITFUNTX Used by NONLINFITTX.
%   FITFUNTX(lambda,t,y) returns the sum of the squares of the 
%   difference  between the data and the values
%   computed by the current function of lambda.
%
%   FITFUN assumes a function of the form
%
%     y =  beta(1)*exp(-lambda(1)*t) + beta(2)*exp(-lambda(2)*t)
%
%   with n linear parameters and n nonlinear parameters.
% last modified by KAM, 11/30/04

% CALCULATE THE GOODNESS-OF-FIT
X(:,1) = exp(-lambda(1)*t);
X(:,2) = exp(-lambda(2)*t);
beta = X\y;
yfit = X*beta;
err = sum((yfit-y).^2);

% update the graph and pause
set(gcf,'DoubleBuffer','on')
set(handle,'ydata',yfit)
drawnow
pause(.04)
