Fitting to a homemade function
조회 수: 3 (최근 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!