function sse = fitrho(lambda,t,y)
%   fitrho(lambda,t,y) returns the error (SSE) between the data and the values
%   computed by the current function of lambda AND the initial magnetization
%   delta_I_zero
%
%   fitrho assumes a function of the form
%
%     y =  c(1)*exp(-lambda(1)*t) + ... + c(n)*exp(-lambda(n)*t)
%
%   with n linear parameters and n nonlinear parameters.
%
%   y is the absolute diagonal peak and c is the initial magnetization.
%
%   In this special case the function is used with lambda as a single value

A = zeros(length(t),length(lambda));
for j = 1:length(lambda)
   A(:,j) = exp(-lambda(j)*t);
end


c = A\y;                % calculate the constant(s) c
% c is delta_I_zero, the initial magnetization
assignin('base','delta_I_zero', c) % export c to the workspace

z = A*c;              % estimated y vector

sse = norm(z-y)^2;     % Sum of Square Error 

pearson_diag = corr (z, y);
assignin('base','pearson_diag', pearson_diag) % export pearson_diag to the workspace

Q_diag = norm(z-y)/norm(y);
assignin('base','Q_diag', Q_diag) % export pearson_cross to the workspace
