Difference between predefined and custom exponential fit function

Hello all, I'm trying to define a custom function for fitting some data, of the shape a+b*exp(c*x). But to test whether Im' doing this correctly, I first tried to compare fitting a simple dataset with a predefined expoinential "exp1", and the one that I'd define myself.
x = 1:100;
y = 3*exp(0.2*x); % some random exponential data
f1 = fit(x', y', 'exp1')
This gives the output of
General model Exp1:
f1(x) = a*exp(b*x)
Coefficients (with 95% confidence bounds):
a = 3 (3, 3)
b = 0.2 (0.2, 0.2)
which is correct.
Now, defining the same thing with fittype:
testexp = fittype('a*exp(b*x)', 'independent', 'x');
f2 = fit(x', y', testexp)
gives the output of
General model:
f2(x) = a*exp(b*x)
Coefficients (with 95% confidence bounds):
a = -3.317e-19 (-1.473e-17, 1.407e-17)
b = 0.9402 (0.5052, 1.375)
which is slightly insane.
Can you please tell me what am I doing wrong?
Kind regards, Marko

 採用された回答

Steven Lord
Steven Lord 2016 年 9 月 6 日

1 投票

As described in the "Optimized Starting Points and Default Constraints" section of this documentation page, when you use the predefined exponential model it uses a heuristic to determine the starting point. When you use a custom nonlinear model, it uses a random starting point.
You can specify a starting point using the fitoptions function. Given that your model to fit includes exp(b*100) which for something as small as b = 0.5 is on the order of 5e21, I think the better a starting guess you can specify for the b coefficient the more likely it is that your fitting will succeed.

1 件のコメント

Marko Filipovic
Marko Filipovic 2016 年 9 月 6 日
Yes, you were right. When I introduced starting points closer to the actual values, the results were definitely better, but still pretty bad. But when I constrained x to go to 10 instead of to 100, even without starting values fit found the correct answer quickly. Thank you for your help!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLinear and Nonlinear Regression についてさらに検索

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by