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.
  2 件のコメント
Renee
Renee 2015 年 3 月 4 日
Did you ever find a solution? I'm trying to do this also
Torsten
Torsten 2015 年 3 月 4 日

サインインしてコメントする。

回答 (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 Center および File ExchangeGet 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