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

36 Ansichten (letzte 30 Tage)
Anup
Anup am 6 Nov. 2022
Beantwortet: Steven Lord am 6 Nov. 2022
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?

Akzeptierte Antwort

John D'Errico
John D'Errico am 6 Nov. 2022
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.

Weitere Antworten (1)

Steven Lord
Steven Lord am 6 Nov. 2022
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.

Kategorien

Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by