# Fitting an exponential function: Setting options?

1 回表示 (過去 30 日間)
Caroline Otto 2021 年 2 月 15 日
コメント済み: Caroline Otto 2021 年 2 月 16 日
Hello,
I would like to fit a custom specific equation and get an error message. My code is as follows:
T_K = [250.150000000000 253.150000000000 263.150000000000 273.150000000000 283.150000000000 293.150000000000 303.150000000000 313.150000000000 323.150000000000 333.150000000000 343.150000000000 353.150000000000 363.150000000000 373.150000000000 383.150000000000 393.150000000000 403.150000000000 413.150000000000 423.150000000000 433.150000000000 443.150000000000 453.150000000000 463.150000000000 473.150000000000 483.150000000000 493.150000000000 503.150000000000 513.150000000000 523.150000000000 533.150000000000 543.150000000000 553.150000000000 563.150000000000 573.150000000000 583.150000000000 593.150000000000 603.150000000000 613.150000000000]'
d = [985 983 976 969 962 955 948 940 933 926 919 912 904 897 890 882 875 867 859 852 844 836 828 820 812 803 795 786 777 768 759 750 740 730 720 710 699 688]'
f = fittype('A/(B * exp(1+ (1 - T_K/C)^D))',...
'dependent',{'d'},'independent',{'T_K'},...
'coefficients',{'A','B','C','D'});
fit2 = fit(T_K, d, f);
The error I get is in the fit function: [fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
My idea was that it could be a mathematical problem with the exponential function. After having read this I tried to set some options (lower bounds, where I was not sure about the order:
options = fitoptions('A/(B * exp(1+ (1 - T_K/C)^D))', 'Lower', [0 Inf Inf 1]);
), but it was without success. Does anybody has an idea about what is wring or the problem could be?
##### 4 件のコメント2 件の古いコメントを表示2 件の古いコメントを非表示
Walter Roberson 2021 年 2 月 15 日
You did not say what the error is ?
Caroline Otto 2021 年 2 月 15 日
Error using fit>iFit (line 348)
Complex value computed by model function, fitting cannot continue.
Try using or tightening upper and lower bounds on coefficients.
Error in fit (line 116)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
Error in Umrechnung_Polynom (line 36)
fit2 = fit(T_K, d, f);

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

### 採用された回答

Walter Roberson 2021 年 2 月 15 日

options = fitoptions('A/(B * exp(1+ (1 - T_K/C)^D))', 'Lower', [0 Inf Inf 1]);
You set the lower bounds for B and C to infinity?? You divide by C so if C is infinite T_K/C would be sign(T_K)*0
If T_K/C > 1 then 1-T_K/C would be negative, and negative ^D would be complex if D is not an integer. So you need to ensure T_K/C <= 1 so T_K <= C and C should have a lower bound of max(T_K)
##### 6 件のコメント4 件の古いコメントを表示4 件の古いコメントを非表示
Alex Sha 2021 年 2 月 16 日

As commented by David, if you don't drop the B or A, there will be multi-solutions, with the different combinations of A and B, but unique of C and D:
1:
Root of Mean Square Error (RMSE): 1.0064732367416
Sum of Squared Residual: 38.4935582985301
Correlation Coef. (R): 0.999934086786684
R-Square: 0.99986817791792
Parameter Best Estimate
---------- -------------
a -46890.8524606817
b -5.63376277792465
c 1128.65575737085
d -0.508557122720511
2:
Root of Mean Square Error (RMSE): 1.0064732367416
Sum of Squared Residual: 38.4935582985303
Correlation Coef. (R): 0.999934086786694
R-Square: 0.99986817791794
Parameter Best Estimate
---------- -------------
a 103527.516316089
b 12.4384487994102
c 1128.6557688586
d -0.508557130714601
3:
Root of Mean Square Error (RMSE): 1.0064732367416
Sum of Squared Residual: 38.4935582985303
Correlation Coef. (R): 0.999934086786667
R-Square: 0.999868177917885
Parameter Best Estimate
---------- -------------
a 17590.6485257921
b 2.11345146634875
c 1128.65575372825
d -0.508557120581391
...
If drob B, the fitting equation becomes: y = A/(exp(1+ (1 - x/C)^D));
There will be an unique result:
Root of Mean Square Error (RMSE): 1.00647323674159
Sum of Squared Residual: 38.4935582985297
Correlation Coef. (R): 0.999934086786666
R-Square: 0.999868177917884
Parameter Best Estimate
---------- -------------
a 8323.18547243371
c 1128.6557657083
d -0.508557129233705
While If drob A, the fitting equation becomes: y = 1/(B * exp(1+ (1 - x/C)^D));
There will also be an unique result:
Root of Mean Square Error (RMSE): 1.0064732367416
Sum of Squared Residual: 38.4935582985304
Correlation Coef. (R): 0.999934086786664
R-Square: 0.999868177917879
Parameter Best Estimate
---------- -------------
b 0.000120146307262581
c 1128.65577814606
d -0.508557138276278
Caroline Otto 2021 年 2 月 16 日
Yes, that's what I wanted to get. Thank you so much for this helpful answer. To be honest, I had to adapt the bound for D to get this solution, but now it works.

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

### カテゴリ

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