Note: LSQCURVEFIT can be used to solve nonlinear curve-fitting (data-fitting) problems in least-squares sense. The LSQCURVEFIT function uses the same algorithm as LSQNONLIN, but simply provides a convenient interface for data-fitting problems.
To do this, create the following function named fit_simp.m which uses the X and Y data, both of which are passed into lsqnonlin as optional input arguments. Use the X data to calculate values for f, and subtract the original Y data from this. The results are the differences between the experimental data and the calculated values. The lsqnonlin function will minimize the sum of the squares of these differences.
function diff = fit_simp(x,X,Y)
diff = A + B.*exp(C.*X) + D.*exp(E.*X) - Y;
The following script is an example of how to use fit_simp.m:
X0=[1 1 1 1 1]';
Y_new = x(1) + x(2).*exp(x(3).*X)+x(4).*exp(x(5).*X);