Non linear fit

7 views (last 30 days)
Camil
Camil on 2 Dec 2011
Hi,
I will have to fit some experimental data. For now I use the data coming from a numerical model to test my fitting codes. The model equation we are using is: y=((x.^6).*a0+(x.^4).*a1+(x.^2)*a2)./((x.^4).*a3+(x.^2).*a4+1);.
So here is the simplified code to get the model data:
--------------------------------------
clear all
A0=2.184627599999999e-21;
A1=-1.870665659314032e-18;
A2=4.004561299600000e-16;
A3=5.461568999999997e-06;
A4=-0.004673999968285;
X=19.8857:0.00001:21.4881;
Y=((X.^6).*A0+(X.^4).*A1+(X.^2)*A2)./((X.^4).*A3+(X.^2).*A4+1);
figure
plot(X,Y)
---------------------------------------------------------
Now I would like to fit the data from X and Y with and equation of the form y=((x.^6).*a0+(x.^4).*a1+(x.^2)*a2)./((x.^4).*a3+(x.^2).*a4+1). Normally if it works well the fit should give me back my parameter so ao~=A0, a1~=A1, etc.
I tried many thing with cftool, but I never get good results. My best results where when I gave the parameter's initial value very close to their real value (obviously). As soon as I get a little far from the real value the fit doesn't work at all. Any ideas? With my experimental data I will be able to get a precise value for a3, but I will have to guess the others.
Any suggestions on how to fit this data with this equation?
Thank you very much

Answers (2)

the cyclist
the cyclist on 3 Dec 2011
I think that the very sharp spike in the functional form (between 20.6 and 20.8) is going to make this very difficult to fit. I would think that the nlinfit() function in the Statistics Toolbox is probably your best bet, as you can define the exact form you want.
I also wonder if taking the log before fitting might be a bit more stable, but I'm not sure.

Matt Tearle
Matt Tearle on 6 Dec 2011
Hmm... I thought I'd answered before, but apparently not. Oh well. As the cyclist says, the very tight spike in the middle makes this a difficult function to fit. Then add to that the wide range of parameter values (1e-3 to 1e-21), plus how sensitive the function is to those parameters. End result: this is going to be very difficult.
As a simple experiment to see the issues involved, just play with some of the parameter values and rerun the code you posted. Look at the difference in the plot if you multiply A2 by 0.9999, for instance. Now imagine trying to find the "best" fit by iteratively tweaking 5 parameters, when changes of a fraction of a percent make such a huge difference.
You can factor out 1e-16 from the numerator (and throw it away, if you just rescale Y), so you can probably avoid precision issues, but not the sensitivity.

Categories

Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!