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

37 visualizaciones (últimos 30 días)
Anup
Anup el 6 de Nov. de 2022
Respondida: Steven Lord el 6 de Nov. de 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?

Respuesta aceptada

John D'Errico
John D'Errico el 6 de Nov. de 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.

Más respuestas (1)

Steven Lord
Steven Lord el 6 de Nov. de 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.

Categorías

Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by