curve fitting using custom equation error

4 visualizaciones (últimos 30 días)
jinshah kalluvila
jinshah kalluvila el 1 de Abr. de 2019
Respondida: Matt J el 1 de Abr. de 2019
When i am using a custome equation with prediefined variables included, i am getting an error
Error using fittype/testCustomModelEvaluation (line 16)
Custom equations must produce an output vector, matrix, or array that is the same
size and shape as the input data. This custom equation fails to meet that
requirement:
a/(exp((x-M)/(b*St))+1)
Error in fittype>iCreateFittype (line 371)
testCustomModelEvaluation( obj );
Error in fittype (line 328)
obj = iCreateFittype( obj, varargin{:} );
Error in createFit (line 22)
ft = fittype(@(a,b,x) a/(exp((x- M)/(b*St))+1), 'independent', 'x', 'dependent',
'y','coefficients', {'a','b'} );
Here is my code for lotting the curve...
function [fitresult, gof] = createFit(XbyL, S)
[xData, yData] = prepareCurveData( XbyL, S );
M = mean(S)
St = std(S)
% Set up fittype and options.
ft = fittype(@(a,b,x) a/(exp((x- M)/(b*St))+1), 'independent', 'x', 'dependent', 'y','coefficients', {'a','b'} );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.649115474956452 0.73172238565867];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
%figure( 'Name', 'untitled fit 1' );
%h = plot( fitresult, xData, yData );
%legend( h, 'S500 vs. X500', 'untitled fit 1', 'Location', 'NorthEast' );
% Label axes
%xlabel XbyL
%ylabel S
%grid on

Respuestas (1)

Matt J
Matt J el 1 de Abr. de 2019
ft = fittype(@(a,b,x) a./(exp((x- M)./(b.*St))+1), 'independent', 'x', 'dependent',
'y','coefficients', {'a','b'} );

Categorías

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

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by