フィルターのクリア

Setting bounds for constants in a fit() object in terms of other constants in the fit object

53 ビュー (過去 30 日間)
Seo Kyung Ahn
Seo Kyung Ahn 2024 年 7 月 19 日 2:43
編集済み: Matt J 2024 年 7 月 20 日 1:46
Hello, I am currently trying to fit experimental data that I theorize fits a logarithmic function.
To this end, I am using the fit() and fitoptions() function in order to create a logarithmic equation.
Since the default MATLAB logarithmic fit model does not seem to account for horizontal translation and scaling, I have created a custom fit type as seen below:
shiftedLog = fittype('A*log((B*x)-C) + D', 'independent', 'x', 'coefficients', {'A','B','C','D'});
% set the bounds
opts.StartPoint = [...]; % Initial guesses for [A, B, C, D]
opts.Lower = [...]; % Lower bounds for [A, B, C, D]
opts.Upper = [...]; % Upper bounds for [A, B, C, D]
I have noticed that when I try to run this program, I have ran into errors where the fit object returns either infinity or a complex value.
Since the log() function is defined only when its inner argument > 0, I need to specify the bounds for variables B and C to keep the entire argument positive.
However, When I try to specify the bounds in terms of the constants of the fit object, for example:
opts.Lower = [-Inf, C/min(x),...]
MATLAB gives me an error.
I know that in the main script code, the constants A, B, C, and D are not standalone variables so the main script has this issue, but as (to my knowledge) fit() finds the best values for the constants through an iterative process. Given this, It is impractical to specify a hard-coded value for the limits.
How should I approach this problem? Is there another way to find fit of a logarithmic function that incorporates 'shifting' and 'stretching' in both horizontal and vertical directions? Or is there a workaround? Thank you in advance.
  2 件のコメント
Mathieu NOE
Mathieu NOE 2024 年 7 月 19 日 9:09
can you share some data ? and IC for the fit
Matt J
Matt J 2024 年 7 月 19 日 11:20
編集済み: Matt J 2024 年 7 月 19 日 15:02
The model is over-parametrized. The D parameter can be removed.
To see this, make the change of variables D=A*log(E). Then the model becomes,
y = A*log(B*x-C)+A*log(E)
= A*log(B*E*x-C*E)
which is equivalent to the 3-parameter model,
y = A*log(b*x-c)

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

採用された回答

Matt J
Matt J 2024 年 7 月 19 日 11:02
編集済み: Matt J 2024 年 7 月 20 日 1:46
As a more indirect approach, instead of fitting,
y=A*log(B*x-C) %D has been deliberately removed - it is unnecessary
you could invert the model equation and fit,
x=(1/B)*exp(y/A) + C/B
which is the same as,
x=a*exp(b*y)+c
which is the same as the built-in 'exp2' fittype with d=0.
If you like, you can then go back to your original formulation, using the above fit to derive the StartPoint. Hopefully, this will put you close enough to the solution that B*x-C>0 will be innately satisfied.

その他の回答 (1 件)

Torsten
Torsten 2024 年 7 月 19 日 9:47
編集済み: Torsten 2024 年 7 月 19 日 9:48
Use "lsqcurvefit" and set A(1,2) = -1, A(1,3) = 1/min(x) and b(1) = 0 for the linear constraint condition A*x<=b.

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by