LSQCURVEFIT simultaniously on 4 datasets and 2 functions

조회 수: 6 (최근 30일)
Romeo Van Snick
Romeo Van Snick 2011년 12월 21일
댓글: Yingbo Li 2023년 8월 15일
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.

답변 (1개)

Matt J
Matt J 2015년 3월 4일
편집: Matt J 2015년 3월 4일
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
Yingbo Li
Yingbo Li 2023년 8월 15일
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 . :-)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by