FUNCTION REFERENCE
fit
Fit a curve or surface model to data by least squares or interpolation.
Fit a curve or surface model to data by least squares or interpolation.
Syntax
fitobject = fit(x, y, fitType)Syntax
fitobject = fit([x y], z, fitType)Syntax
[fitobject, gof, output] = fit(x, y, fitType, fitOptions, Name, Value, ...)fitType is a library model name (poly1..poly9, poly00..poly55, exp1, exp2, fourier1..fourier8, gauss1..gauss8, power1, power2, rat01..rat55, sin1..sin8, weibull, linearinterp, nearestinterp, pchipinterp, cubicinterp, smoothingspline), a custom equation such as 'a*exp(-b*x)+c', a cell array of linear terms, an anonymous function or a fittype. Polynomial and linear models are solved by column-pivoted QR; nonlinear models by a bounded Levenberg-Marquardt (trust-region) iteration from a start point computed from the data (custom equations without StartPoint use a fixed pseudo-random start and warn). Name-value options: StartPoint, Lower, Upper, Weights, Exclude (logical mask or indices), Normalize ('on' centers and scales x by its mean and standard deviation; coefficients then refer to the scaled x), Robust ('off', 'LAR', 'Bisquare'), Algorithm ('Trust-Region', 'Levenberg-Marquardt'), MaxIter, MaxFunEvals, TolFun, TolX, Display, SmoothingParam (smoothingspline only; between 0 and 1, default from the data as in csaps) and problem (values of problem parameters). gof has sse, rsquare, dfe, adjrsquare and rmse; output has numobs, numparam, residuals, Jacobian, exitflag, iterations, funcCount, firstorderopt, algorithm and message, plus p (the smoothing parameter used) for smoothingspline.
Example
f = fit((1:5)', [2.1 3.9 6.2 7.8 10.1]', 'poly1'); coeffvalues(f)Example
[f, ~, out] = fit((0:5)', [0 1.1 1.9 3.2 3.8 5.1]', 'smoothingspline', 'SmoothingParam', 0.8); out.p % 0.8Example
[f, gof] = fit((0:0.5:3)', 2*exp(0.7*(0:0.5:3))', 'exp1'); gof.dfe % 5Differences from MATLAB: converged nonlinear fits take a few extra Gauss-Newton steps, so results are the least-squares optimum even with loose TolFun/TolX. Rows as well as columns are accepted for curve data. Problem parameters are scalars. Lowess and loess, biharmonic and thin-plate interpolants, surface interpolants and fittype 'options' are not supported yet. Interpolant and smoothing-spline fits average repeated x values (smoothing splines with the weights summed); a smoothing spline's gof has dfe 0, like an interpolant. Robust fits use leverage-adjusted residuals with the MAD/0.6745 scale about the median; their confidence bounds use the final robust weights.
These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.