LSQCURVEFIT simultaniously on 4 datasets and 2 functions

6 visualizaciones (últimos 30 días)
Romeo Van Snick
Romeo Van Snick el 21 de Dic. de 2011
Comentada: Yingbo Li el 15 de Ag. de 2023
I have 4 data sets, two of which comply to a fit function f1, and two of which comply to a fit function f2. These fit functions are of the form:
f1 = @(A,t_1, t_2,t) A*(1+4/5*exp(-t/t_1))*exp(-t/t_2)
f2 = @(A,t_1, t_2,t) A*(1-2/5*exp(-t/t_1))*exp(-t/t_2)
where t is the data. I need to fit these two functions to the four dataset simultaneously, because the t_1 and t_2 parameters should be equal for all data. The A parameter differs though. I can match the A parameter already for two datasets by looking at the tails of the set ( where the first exponential vanishes, the other two are impossible because they are shorter, yet more detailed) so this gives me 5 parameters:
  • A_1
  • A_2
  • A_34 (is already matched for data set 3 and 4)
  • t_1
  • t_2
How would I do this?
I've tried using
% P = [A_34, A_1, A_2, t_1, t_2];
errf = @(P) sum( (f_1( P(1), P(4), P(5), x_3) - y_3).^2 + ...
sum( (f_2( P(1), P(4), P(5), x_4) - y_4).^2 + ...
sum( (f_1( P(2), P(4), P(5), x_1) - y_1).^2 + ...
sum( (f_2( P(3), P(4), P(5), x_2) - y_2).^2;
P0 = [1000, 1000, 1000, 0.05, 5];
P = fminsearch(errf,P);
Notice the the set 3 belongs to f_1 and set 4 to f_2, yet I can determine their relative scale by looking at the tail (where the first exponential vanishes).
This give me bad fits though. Is there a way I can do this better? I can fit each dataset using LSQCURVEFIT, but I don't see how to use it on multiple datasets/functions.
I hope this is a clear explanation.

Respuestas (1)

Matt J
Matt J el 4 de Mzo. de 2015
Editada: Matt J el 4 de Mzo. de 2015
The curve function that you fit using lsqcurvefit is allowed to be vector-valued. Define the curve function to have a 2x1 vector-valued output [f1;f2] and use lsqcurvefit as normal.
Similarly, there is no need to treat t1 and t2 as separate. Just concatenate them t=[t1,t2] and feed to lsqcurvefit in the usual way. Inside the definition of the curve function, you can split t into parts and use those subsets where appropriate.
  1 comentario
Yingbo Li
Yingbo Li el 15 de Ag. de 2023
can you take his problem and make an example? I have trouble following your comments. you are a level 10, and most people are level 1 . :-)

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by