The StartPoint of Curve Fitting of the Function f(x)=a*exp(-x/b)+c
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Shilin Shi
am 15 Feb. 2022
Beantwortet: Walter Roberson
am 15 Feb. 2022
I am trying to fit the curve f(x)=a*exp(-x/b)+c , but the startpoints influences the results, besides, the result of b is the same with the initial value, how can I solve this?
x=[10,30,60,120,180,300,420,600,900,1200,1500,1800,2100,2400,2700,3000,3600];
y=[7.23E-08,6.83E-08,6.58E-08,5.86E-08,5.52E-08,4.54E-08,3.97E-08,3.43E-08,2.77E-08,2.17E-08,
1.86E-08,1.44E-08,1.19E-08,1.02E-08,9.4E-09,8.7E-09,6.2E-09];
f1=fittype('a*exp(-x/b)+c','independent','x','coefficients',{'a','b','c'});
opts=fitoptions('Method','NonlinearLeastSquares');
opts.StartPoint=[1e-8,1000,1e-8];%if I set the value as 1 1 1 the result is poor%
opts.Display='Off';
[result,gof]=fit(x,y,f1,opts);
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 15 Feb. 2022
If we try to solve symbolically, and use calculus
x=[10,30,60,120,180,300,420,600,900,1200,1500,1800,2100,2400,2700,3000,3600];
y=[7.23E-08,6.83E-08,6.58E-08,5.86E-08,5.52E-08,4.54E-08,3.97E-08,3.43E-08,2.77E-08,2.17E-08,1.86E-08,1.44E-08,1.19E-08,1.02E-08,9.4E-09,8.7E-09,6.2E-09];
syms a b c
model_y = a*exp(-x/b)+c
r1 = vpa(sum((y - model_y).^2))
dr1 = diff(r1, a)
partiala = solve(dr1, a)
r2 = subs(r1, a, partiala)
dr2 = diff(r2, c)
partialc = solve(dr2, c)
r3 = subs(r2, c, partialc); %very long expression!
dr3 = diff(r3, b);
partialb = vpasolve(dr3, b);
bestb = partialb
bestc = vpa(subs(partialc, b, bestb))
besta = vpa(subs(subs(partiala, c, bestc),b,bestb))
but in practice, the attempt to solve() dr2 for c takes a very long time.
But r1 is a function of two variables, so you could try to plot it and look for minima. Or you could plot dr2 and look for minima.
When I explore, I find that there is a range of b values near 0 for which the values are imaginary, but that the functions are well defined if you take b a bit more negative or a bit more positive. And when I explore dr2 (the derivative with respect to c), I see that it is asymptopic towards 0 on both sides away from b = 0.
What that implies is that the system does not have a finite global minima. That any numeric exploration of the minima is going to stop when it hits the limit of numeric accuracy.
With the derivative going to 0 at the infinite limit of b, then examining the model we can see that the implication is that you can get a better fit from using the model that a = 0, b (not 0, not -infinity, could be +infinity, but finite non-zero is okay), c = mean(y) . Or a = finite, b = +infinity, c = mean(y) . To phrase that another way, dropping the term a*exp(-x/b) appears to give you a better fit. Not a good fit, but better than you can get with any finite non-zero b.
0 Kommentare
Weitere Antworten (1)
Alan Weiss
am 15 Feb. 2022
I think that your data is very small, about order 1e-8 instead of order 1. Here is a little script I knocked together that seems to work reasonably:
xdata = [10,30,60,120,180,300,420,600,900,1200,1500,1800,2100,2400,2700,3000,3600];
ydata = [7.23E-08,6.83E-08,6.58E-08,5.86E-08,5.52E-08,4.54E-08,3.97E-08,3.43E-08,2.77E-08,2.17E-08,...
1.86E-08,1.44E-08,1.19E-08,1.02E-08,9.4E-09,8.7E-09,6.2E-09];
zdata = ydata*1e8; % rescale
fun = @(x)x(1)*exp(-xdata/x(2)) + x(3) - zdata;
sol = lsqnonlin(fun,[1,1000,1]) % Tries to make fun = 0
plot(xdata,zdata,'ro',xdata,fun(sol)+zdata,'kx')
Alan Weiss
MATLAB mathematical toolbox documentation
0 Kommentare
Siehe auch
Kategorien
Mehr zu Curve Fitting Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!