How to define a constant inside the 'fittype' function?

조회 수: 37 (최근 30일)
Anup
Anup 2022년 11월 6일
답변: Steven Lord 2022년 11월 6일
function [fitresult, gof] = createFit(i1, v1,s,T1)
[xData, yData] = prepareCurveData( i1, v1 );
% Set up fittype
ft = fittype( '1.21+(a1+a2.*T1).*x+s.*log((b1+b2./T1+b3./T1.^2).*x+1)', 'independent', 'x', 'dependent', 'y');
Here s and T1 are constant values passed by the function 'createFit()'.
a1,a2,b1,b2,b3 are parameters to be determined based on independent value 'i1' and dependent value 'v1'.
Currently in my code, fittype is treating 's' and 'T' also as parameters.
Is there a way such that fittype function treat 's' and 'T1' as constant values passed from the function but not as the parameters?

채택된 답변

John D'Errico
John D'Errico 2022년 11월 6일
Use a function handle, as documented by fittype.
ft = fittype(@(a1,a2,b1,b2,b3,x) 1.21+(a1+a2.*T1).*x+s.*log((b1+b2./T1+b3./T1.^2).*x+1), 'independent', 'x');
Here I created an anonymous function in the call. If s and T1 exist as variables in your works space, they will be encapsulated into the function handle workspace. x is assumed to be the last variable in the calling list as I recall.

추가 답변 (1개)

Steven Lord
Steven Lord 2022년 11월 6일
Yes, using the 'problem' name-value pair argument to both fittype and fit.
See the "Create Fit Options and Fit Type Before Fitting" example on the documentation page for the fit function. It specifies n as a problem parameter when the fittype is created then specifies a value for it when the fitting is performed.

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by