curve fitting using custom equation error

2 views (last 30 days)
jinshah kalluvila
jinshah kalluvila on 1 Apr 2019
Answered: Matt J on 1 Apr 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

Answers (1)

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

Categories

Find more on Linear and Nonlinear Regression in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!