Add constants in nlinfit

3 ビュー (過去 30 日間)
Silke
Silke 2017 年 12 月 21 日
コメント済み: Star Strider 2017 年 12 月 22 日
Hi there,
is there a way that I provide nlinfit with some constants that are taken into account when solving a function?
So, for example, I use this code for nlinfit:
[xfit,resnorm, Jacob, CovB, MSE] = nlinfit( handles.timecorr,handles.datacorr',@DiffEqSolver300, B );
I would like to give another set of parameters to the function DiffEqSolver300 that should not be fitted, but they depend on calculations that happens before I call the nlinfit function. Is this somehow possible?
Just a simple example. Let's assume the function that should be fitted is
y = A*x + B;
Depending on some input parameters, A could be 1 or 10 or 100 and B is a fitting parameter. How can I tell the function which value A should have?

採用された回答

Star Strider
Star Strider 2017 年 12 月 21 日
編集済み: Star Strider 2017 年 12 月 21 日
Writing your own objective function, you simply need to pass ‘A’ as a parameter.
Example
objfcn = @(B,x,A) A*x + B;
then call it in nlinfit as:
beta = nlinfit(x, y, @(B,x) objfcn(B,x,A), ... );
so that ‘objfcn’ accepts ‘A’ as a parameter, and the function works with nlinfit as it would if no additional parameters were passed.
  6 件のコメント
Silke
Silke 2017 年 12 月 22 日
Thanks for your help. Indeed, it is working now. I had an error in DiffEqSolver300.
Star Strider
Star Strider 2017 年 12 月 22 日
As always, my pleasure.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by