| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Statistics Toolbox |
| Contents | Index |
| Learn more about Statistics Toolbox |
beta = nlinfit(X,y,fun,beta0)
[beta,r,J,COVB,mse] = nlinfit(X,y,fun,beta0)
[...] = nlinfit(X,y,fun,beta0,options)
beta = nlinfit(X,y,fun,beta0) returns a vector beta of coefficient estimates for a nonlinear regression of the responses in y on the predictors in X using the model specified by fun. X is an n-by-p matrix of p predictors at each of n observations. y is an n-by-1 vector of observed responses. fun is a function handle to a function of the form:
yhat = modelfun(b,X)
where b is a coefficient vector. beta0 is a vector containing initial values for the coefficients. beta is the same length as beta0.
[beta,r,J,COVB,mse] = nlinfit(X,y,fun,beta0) returns the fitted coefficients b, the residuals r, the Jacobian J of fun, the estimated covariance matrix COVB for the fitted coefficients, and an estimate mse of the variance of the error term. You can use these outputs with nlpredci to produce error estimates on predictions, and with nlparci to produce error estimates on the estimated coefficients. If you use the robust fitting option (see below), you must use COVB and may need mse as input to nlpredci or nlparci to insure that the confidence intervals take the robust fit properly into account.
[...] = nlinfit(X,y,fun,beta0,options) specifies control parameters for the algorithm used in nlinfit. options is a structure created by a call to statset. Applicable statset parameters are:
'MaxIter' — Maximum number of iterations allowed. The default is 100.
'TolFun' — Termination tolerance on the residual sum of squares. The defaults is 1e-8.
'TolX' — Termination tolerance on the estimated coefficients beta. The default is 1e-8.
'Display' — Level of display output during estimation. The choices are
'off' (the default)
'iter'
'final'
'DerivStep' — Relative difference used in finite difference gradient calculation. May be a scalar, or the same size as the parameter vector b0. The default is eps^(1/3).
'FunValCheck' — Check for invalid values, such as NaN or Inf, from the objective function. Values are 'off' or 'on' (the default).
'Robust' — Invoke robust fitting option. Values are 'off' (the default) or 'on'.
'WgtFun' — A weight function for robust fitting. Valid only when 'Robust' is 'on'. It can be 'bisquare' (the default), 'andrews', 'cauchy', 'fair', 'huber', 'logistic', 'talwar', or 'welsch'. It can also be a function handle that accepts a normalized residual as input and returns the robust weights as output.
'Tune' — The tuning constant used in robust fitting to normalize the residuals before applying the weight function. The value is a positive scalar, with the default value dependent on the weight function. This parameter is required if the weight function is specified as a function handle.
Note Robust nonlinear fitting uses an algorithm that iteratively reweights response values and recomputes a least-squares fit. The least-squares component of the algorithm differs from linear least squares, but the reweighting loop is identical to that for robust linear methods. In particular, the weight function and its tuning parameter are the same as described for robustfit. Note that nlinfit counts iterations of both the reweighting loop and the least-squares fit toward the maximum number of iterations. |
nlinfit treats NaNs in y or modelfun(beta0,X) as missing data and ignores the corresponding rows.
nlintool is a graphical user interface to nlinfit.
The data in reaction.mat are partial pressures of three chemical reactants and the corresponding reaction rates. The function hougen implements the nonlinear Hougen-Watson model for reaction rates. The following fits the model to the data:
load reaction
beta = nlinfit(reactants,rate,@hougen,beta)
beta =
1.2526
0.0628
0.0400
0.1124
1.1914[1] Seber, G. A. F., and C. J. Wild. Nonlinear Regression. Hoboken, NJ: Wiley-Interscience, 2003.
![]() | net (qrandset) | nlintool | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |