curve fitting using custom equation error
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Matt J
2019-4-1
ft = fittype(@(a,b,x) a./(exp((x- M)./(b.*St))+1), 'independent', 'x', 'dependent',
'y','coefficients', {'a','b'} );
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!