Exponential fitting of data not working

4 visualizaciones (últimos 30 días)
Henry
Henry el 9 de Ag. de 2023
Comentada: Torsten el 9 de Ag. de 2023
I have a vector of 1666 values with an exponential curve. Since this vector is the result of a experimental measurement I don't have the precise law that describes it but I need its horizontal asymptotic value. To get it I thought about an exponential fitting following the model a+b*exp(-c*t) but all the methods I tried result in either an error or a straight line. What am I missing?
I've attached a .mat file containing the T_A vector (temperature measurements). t_A vector is time and can be assumed as:
t_A=linspace(0,83.3,1666);
Edit: I included another vector T_B, with which fit or other methods don't work. You can assume t_B is defined the same way as t_A.
Things I've tried:
g = fittype('a-b*exp(-c*x)'); % a is asymptotic value
fA = fit(t_A,T_A,g,'StartPoint',[[ones(size(t_A)), -exp(-t_A)]\T_A; 1]);
Gives back "Inf computed by model function, fitting cannot continue.". I also tried to change the upper and lower bounds like it suggests but no luck. Changed starting points as well, no luck.
f = @(A,t_A) A(1)+A(2).*exp(-t_A.*(A(3)));
beta = lsqcurvefit(f,[[ones(size(t_A)), -exp(-t_A)]\T_A; 1],t_A,T_A);
Gives back "Local minimum possible" but the plot looks like a spike in 0 and then goes back to 0 and stays there
f = @(A,t_A) A(1)+A(2).*exp(-t_A.*(A(3)));
A_s = fminsearch(@(A) norm(T_A - f(A,t)), [-exp(-t_A); 1; ones(size(t_A)); 1]);
Runs infinitely, doesn't stop.
I also tried curveFitter but gives out the same results as fit (or an ugly exponential curve when it works), but it's not an optimal solution since I would have to do this numerous timesn and I'd like an automated approach.
I've never done curve fitting and I'm trying now since I need it. Would love a solution but also some insight as to why it doesn't work or how I can improve. Thank you very much to all of you.

Respuestas (2)

Cris LaPierre
Cris LaPierre el 9 de Ag. de 2023
Editada: Torsten el 9 de Ag. de 2023
For attempts 2 and 3, what is A?
First one seems to work.
load T_A.mat
t_A=linspace(0,83.3,1666)';
g = fittype('a-b*exp(-c*x)'); % a is asymptotic value
fA = fit(t_A,T_A,g,'StartPoint',[[ones(size(t_A)), -exp(-t_A)]\T_A; 1])
fA =
General model: fA(x) = a-b*exp(-c*x) Coefficients (with 95% confidence bounds): a = 62.01 (61.98, 62.04) b = 35.24 (35.21, 35.27) c = 0.03484 (0.03475, 0.03493)
plot(fA,t_A,T_A)
  2 comentarios
Henry
Henry el 9 de Ag. de 2023
Thank you for your response. For 2 and 3, A's are the coefficients of the exponential function, the ones the fitting needs to find.
I can't believe that it works for you. I can't believe that it works for me now too. I swear I've been trying all morning. Would you be willing to try with another vector? This one doesn't seem to work.
Cris LaPierre
Cris LaPierre el 9 de Ag. de 2023
What happens when you try it? What does 'doesn't work' mean?
load T_B.mat
t_A=linspace(0,83.3,1666)';
g = fittype('a-b*exp(-c*x)'); % a is asymptotic value
fA = fit(t_A,T_B,g,'StartPoint',[[ones(size(t_A)), -exp(-t_A)]\T_B; 1])
fA =
General model: fA(x) = a-b*exp(-c*x) Coefficients (with 95% confidence bounds): a = 62.04 (62.01, 62.08) b = 35 (34.97, 35.03) c = 0.03482 (0.03473, 0.03492)
plot(fA,t_A,T_B)

Iniciar sesión para comentar.


Torsten
Torsten el 9 de Ag. de 2023
Editada: Torsten el 9 de Ag. de 2023
A = load("T_A.mat");
A = A.T_A;
A = [linspace(0,83.3,1666).',A];
plot(A(:,1),A(:,2),'o')
hold on
p0 = [25 1 1];
f = @(p)p(1)+p(2)*exp(-p(3)*A(:,1));
F = @(p)f(p)-A(:,2);
p = lsqnonlin(F,p0,[],[],optimset('MaxIter',1000000,'MaxFunEvals',1000000))
Local minimum possible. lsqnonlin stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
p = 1×3
62.0057 -35.2389 0.0348
norm(F(p))
ans = 6.4488
plot(A(:,1),f(p))
plot([0 100],[p(1),p(1)],"k")
hold off
  2 comentarios
Henry
Henry el 9 de Ag. de 2023
Editada: Henry el 9 de Ag. de 2023
Hello, thank you for your response. Can you explain how your code works? Especially why you put the T_A vector inside another vector with the t_A vector. Couldn't I use them separately?
Also, I'm assuming that the asymptotic value is p(1), correct? How can I plot the obtained function to visualize the asymptote?
Torsten
Torsten el 9 de Ag. de 2023
Can you explain how your code works? Especially why you put the T_A vector inside another vector with the t_A vector. Couldn't I use them separately?
Yes, you could.
Also, I'm assuming that the asymptotic value is p(1), correct? How can I plot the obtained function to visualize the asymptote?
Done.

Iniciar sesión para comentar.

Categorías

Más información sobre Fit Postprocessing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by