Need help fitting nonlinear model to data

7 visualizaciones (últimos 30 días)
Chris
Chris el 26 de Jul. de 2013
Hi,
I have a set of data that I would like to fit to the logistical function 1/(A+B*exp(-C*x)). I attempted to to do this by using the function NonLinearModel.fit but for some reason it is not workking.
CODE:
Data = ...
[0.0000 0.1700
1.0000 0.2000
1.5000 0.9900
1.6000 1.5600
1.8000 3.5500
2.0000 4.5200
2.2500 11.1400
2.3000 13.2700
2.4000 16.0000
2.5500 22.6500
2.6100 25.3000
2.7000 29.5700
2.7500 31.6500
2.8000 33.9100
2.9000 39.1300
2.9400 40.6000
3.0000 42.5500
3.1000 45.1200
3.1500 46.3100
3.2000 47.1800
3.3000 48.6300
3.4500 50.0400
3.5000 50.3400
3.5500 50.5500
3.6000 50.7200
3.7000 50.9300
3.8000 51.0400
3.8800 51.1000
3.9600 51.1300
4.0000 51.1400
4.1000 51.1600
4.3000 51.1700
4.6000 51.1800
5.0000 51.1800];
xData = Data(:,1);
yData = Data(:,2);
x1 = xData';
LF = @(b,xData)(1/(b(1)+b(2)*exp(-b(3)*x1)));
IPP = [0.0185 360 3.5]';
Lmodel = NonLinearModel.fit(xData,yData,LF,IPP);
Here are the errors that are displayed in the command window after running the code:
Error using nlinfit (line 142)
Error evaluating model function '@(b,xData)(1/(b(1)+b(2)*exp(-b(3)*x1)))'.
Error in NonLinearModel/fitter (line 1121)
[model.Coefs,~,J_r,model.CoefficientCovariance,model.MSE,model.ErrorModelInfo,~] = ...
Error in classreg.regr.FitObject/doFit (line 219) model = fitter(model);
Error in NonLinearModel.fit (line 1484) model = doFit(model);
Error in Model (line 48) Lmodel = NonLinearModel.fit(xData,yData,LF,IPP);
_Caused by:
Error using /
Matrix dimensions must agree._
Any help would be greatly appreciated.

Respuestas (1)

Alan Weiss
Alan Weiss el 29 de Jul. de 2013
Editada: Alan Weiss el 29 de Jul. de 2013
I think you forgot a dot and a ':
LF = @(b,xData)(1./(b(1)+b(2)*exp(-b(3)*x1)))';
You need a dot after the 1 because you don't want matrix division, you want elementwise division. You need a ' at the end to make the answer a column.
Alan Weiss
MATLAB mathematical toolbox documentation

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by