Fitting to a homemade function
4 ビュー (過去 30 日間)
古いコメントを表示
I have created my homemade function based on three parameters where two of them are fixed and the last parameter, D, needs to be tuned in.
ydata=MyFun(a,H,D,xdata)
I would like to use the lsqcurvefit function but how do I tell it that it need to fit to D only, and yet still have a and H as input parameters? Id like to create something as below...
x = lsqcurvefit(@MyFun,a,H,*D*,xdata,ydata)
best Andreas
回答 (2 件)
Adam
2018 年 1 月 25 日
x = lsqcurvefit(@(D, xData) MyFun( a, H, D, xdata ),ydata )
should work, I think...
4 件のコメント
Walter Roberson
2018 年 1 月 26 日
In the expression
@(D, xData) uptake( Var.H, Var.a, D, xData )
xData is a dummy parameter name for a positional parameter that will correspond to some or all of the x data that is passed as the third parameter to lsqcurvefit . I used a different name to emphasize that they are not actually the same variable.
Because parameter passing is positional, without changing the meaning of the expression at all, I could have used something like
@(D, x_data_parameter) uptake( Var.H, Var.a, D, x_data_parameter)
"It seems like the fit only goes through one iteration and sets x=initial guess (D0)"
That is possible, if D0 just happens to generate a residue that is within the tolerance. That can happen due to good initial guess, or due to chance, or due to error in the residue calculation (such as if uptake returned 0), or if the values of the function happen to be naturally small so that the residues come out with small absolute value.
参考
カテゴリ
Help Center および File Exchange で Linear Least Squares についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!