Hello all,
I am having issues while trying to modify a monoexponential curve fitting routine to perform a biexponential fit. I am fairly new to matlab so this is probably the root of my issue. The curve fitting seems to fit the data well, but the output parameters seem incorrect. The exponential fit formula is below:
FittedCurve =A*(exp(-lambda*xdata)) + B*(exp(-lambda2*xdata));
where A and B are the amplitudes each exponential, and lambda and lambda2 are the rate constants for each. These parameters are changing when fitting the same data multiple times...
Here is the curve fitting function code I am using:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [estimates, model] = curvefit_biexp(xdata, ydata)
start_point = rand(1,4);
model =@efun; options = optimset('Display','off','TolFun',1e-16,'TolX',1e-16);
estimates = fminsearch(model, start_point,options);
% expfun accepts curve parameters as inputs, and outputs sse,
% and the FittedCurve.
function [sse,FittedCurve] = efun(v)
A=v(1);
B=v(3);
lambda=v(2);
lambda2=v(4);
FittedCurve =A*(exp(-lambda*xdata)) + B*(exp(-lambda2*xdata));
ErrorVector=FittedCurve-ydata;
sse = sum(ErrorVector .^2);
end
end
Also here is a set of sample data:
xdata=[0;10.7;21.2;31.7;41.9;52.2;62.6;72.6;82.9;92.9;103.2;113.2;123.5;133.8;144;154.3;164.9;175.2;185.5;196;206.9;217.2;227.4;237.7;248.3];
ydata=[-2.5808;-2.1815;-1.6986;-1.2984;-0.9516;-0.7136;-0.4505;-0.3751;-0.3165;-0.2603;-0.2263;-0.1996;-0.1658;-0.1983;-0.2140;-0.2365;-0.1680;-0.1751;-0.1757;-0.1827;-0.1968;-0.1811;-0.1550;-0.1901;-0.1510];
Any help with this issue would be greatly appreciated!!! Thanks in advance...