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

37 次查看(过去 30 天)
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