curve fitting using custom equation error

4 ビュー (過去 30 日間)
jinshah kalluvila
jinshah kalluvila 2019 年 4 月 1 日
回答済み: Matt J 2019 年 4 月 1 日
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

回答 (1 件)

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

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by