# Sub-optimal curve fitting, cannot find asymptotic value

8 views (last 30 days)
Marcus on 14 Sep 2023
Commented: Marcus on 15 Sep 2023
I have two vectors that come from experimental measurements: a voltage vector "Vgen" and a temperature vector "T". I'm trying to fit those vectors with an exponential fitting to calculate their asymptotic values, but fitting is only optimal in the beginning of the curve. I tried using both a double exponential and a sigmoid as fittype's but most of the times I receive a "Inf computed by model function, fitting cannot continue" error. The code I use for fitting is this:
t_HP=linspace(0,83.3,size(T,1)).'; % 83.3 is experiment duration
g = fittype('a-b*exp(-c*x)'); % a is asymptotic value
f0 = fit(t_HP,T,g,'StartPoint',[[ones(size(t_HP)), -exp(-t_HP)]\T; 1]);
xx = linspace(1,1000,100000);
plot(t_HP,T,'k--',xx,f0(xx),'r',"LineWidth",1); % plotting for comparison
%%
tV=linspace(0,83.3,size(Vgen,1))';
g = fittype('a-b*exp(-c*x)'); % a is asymptotic value
fV = fit(tV,Vgen,g,'StartPoint',[[ones(size(tV)), -exp(-tV)]\Vgen; 1]);
xx = linspace(1,1000,100000);
plot(tV,Vgen,'k--',xx,fV(xx),'r',"LineWidth",1); % plotting for comparison
I tried the following fittype
g = fittype('a/(1+exp(-b*x))'); % a is asymptotic value
f0 = fit(t_HP,T,g,'StartPoint',[ones(size(t_HP)), -exp(-t_HP)]\T);
%%
g = fittype('a-b*exp(-c*x)+d*exp(-e*x)'); % a is asymptotic value
f0 = fit(t_HP,T,g,'StartPoint',[[ones(size(t_HP)), -exp(-t_HP)]\T; 1; -exp(-t_HP)\T; 1]);
Is there a way to have a better fitting? Or to make other fittype functions work with this data? I would be happy even if the beginning data is fit sub-optimally, but an accurate asymptotic value is critical. I attached the Vgen and T vectors if anyone wants to try. Thank you everyone in advance.
Edit: is there no other method to estimate asymptotic value from data?

John D'Errico on 14 Sep 2023
Edited: John D'Errico on 14 Sep 2023
I think you do not understand. Estimating an asymptote from data is a problem of extrapolation. It will be strongly dependent on the model you use. The shape of that model will change the estimate of the asymptote, and each of the models you have chosen have a subtly different shape.
The issue of "inf produced by model" is simply an indication that you NEED to provide intelligently chosen starting values for the parameters. Remember that you are using exponentials, and depending on your data, you can easily generate an overflow of double precision arithmetic.
T = LD.T;
Vgen = LD.Vgen;
t_HP=linspace(0,83.3,size(T,1)).'; % 83.3 is experiment duration
plot(t_HP,T) Is there some way to infer the TRUE value for the asymptote at infinity? NO. Even though your data is quite smooth, predicting exactly where that asymptote lies is a difficult problem.
We can view this from a different perspective that may help. I'll transform the problm, plotting instead versus 1./t_HP.
plot(1./t_HP,T)
xlim([0,10]) You should see that the asymptote is now the value of T, where the curve crosses the axis, in the limit at 1./t_HP==0. The problem is, do you see that curve has a nearly infinite slope at zero? Trying to extrapolate to the point where the curve crosses the axis will be very difficult. Again, it will be completely a function of the shape of the model you decide to employ.
We might hope to use a semi-logx plot to visualize that extrapolated point, again, as 1/t_HP aproaches zero now but again, the shape of that curve near zero is not trivial to extrapolate to zero.
semilogx(1./t_HP,T) If you knew what the model shape SHOULD be, then you can use that model somewhat intelligently. But you don't know anything of the sort. You are just guessing various shapes for a curve that has an upper asymptote. And they will each predict differently.
I'm sorry, but you are getting exactly the results I would expect. Change the model, get a different prediction. And the overflows are also expected. They just mean you need to learn more about double precision arithmetic.
Marcus on 15 Sep 2023
Alright then, how would you solve the problem then? How would you estimate asymptotic value? I understand your concern, but it doesn't solve my problem.
Oh and by the way, changing the model in my case doesn't give me a different prediction, it gives me no prediction at all so I can't evaluate how close or far I am from the fittype I'm using. The only fittype that works is the exponential one. "Why fit no work when should?"