Question

I have data I want to fit an exponential decay of second order to, and it looks like it is working fine. An example file: https://dl.dropboxusercontent.com/u/6170801/example.mat

ty is my data as [x y].

My fittype

Mftype = fittype('A1*exp(-x/t1)+A2*exp(-x/t2)+y0','problem',{'t1','t2'});

I want to have both time constants fix. My fitoptions:

Mfopt = fitoptions('method','nonlinearleastsquares','normalize','on','startpoint',[0 0 0 0],'lower',[0 0 0 -Inf],'upper',[Inf Inf Inf Inf]);

Then I fit:

[MfitObj MfitGdn MfitOut]=fit(ty(:,1),ty(:,2),Mftype,Mfopt,'problem',{tau tau});

The problem is that when calculating specific values of x manually using the calculated fit-coefficients from my fitObject, the resulting y is not part of the fit-curve.

When entering:

figure
plot(ty(:,1),ty(:,2))
ylim([0 10]);xlim([0 1800])
hold on;plot(MfitObj)
y=MfitObj.A1*exp(-400/tau)+MfitObj.A2*exp(-400/tau)+MfitObj.y0;
hold on;plot(400,y,'o');hold off;

you see that the manually calculated value at x=400 does not correspond to the fit function that says to use the same coefficients.

My question is: why? Thanks in advance

Edit: I use Matlab R2010b, default algorithm for curve fitting is Trust-Region, not Levenberg-Marquardt.

Was it helpful?

Solution

I have found the source of this problem: If the fit is normalized, all coefficients get some kind of offset, which is added/subtracted to/from them. But the coefficients are displayed without it, thats why an equation with these coefficients only is different.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top