
% Define the data sets that you are trying to fit the
% function to
X=0:.01:.5;
Y=2.0.*exp(5.0.*X)+3.0.*exp(2.5.*X)+1.5.*rand(size(X));
 
% Initialize the coefficients of the function
X0=[1 1 1 1 1]';
 
% Set an options file for LSQNONLIN to use the
% medium-scale algorithm
options = optimset('Largescale','off');
 
% Calculate the new coefficients using LSQNONLIN
x=lsqnonlin(@fit_simp,X0,[],[],options,X,Y);
 
% Plot the original and experimental data
Y_new = x(1) + x(2).*exp(x(3).*X)+x(4).*exp(x(5).*X);
plot(X,Y,'+r',X,Y_new,'b')