fit curve or surface to data -凯发k8网页登录
fit curve or surface to data
syntax
description
creates a fit to the data using the algorithm options specified by the
fitobject
= fit(x
,y
,fittype
,fitoptions
)fitoptions
object.
creates a fit to the data using the library model fitobject
= fit(x
,y
,fittype
,name=value
)fittype
with additional options specified by one or more name=value
pair arguments. use to display
available property names and default values for the specific library
model.
examples
fit a quadratic curve
load some data, fit a quadratic curve to variables cdate
and pop
, and plot the fit and data.
load census; f=fit(cdate,pop,'poly2')
f = linear model poly2: f(x) = p1*x^2 p2*x p3 coefficients (with 95% confidence bounds): p1 = 0.006541 (0.006124, 0.006958) p2 = -23.51 (-25.09, -21.93) p3 = 2.113e 04 (1.964e 04, 2.262e 04)
plot(f,cdate,pop)
for a list of library model names, see fittype
.
fit a polynomial surface
load some data and fit a polynomial surface of degree 2 in x
and degree 3 in y
. plot the fit and data.
load franke sf = fit([x, y],z,'poly23')
linear model poly23: sf(x,y) = p00 p10*x p01*y p20*x^2 p11*x*y p02*y^2 p21*x^2*y p12*x*y^2 p03*y^3 coefficients (with 95% confidence bounds): p00 = 1.118 (0.9149, 1.321) p10 = -0.0002941 (-0.000502, -8.623e-05) p01 = 1.533 (0.7032, 2.364) p20 = -1.966e-08 (-7.084e-08, 3.152e-08) p11 = 0.0003427 (-0.0001009, 0.0007863) p02 = -6.951 (-8.421, -5.481) p21 = 9.563e-08 (6.276e-09, 1.85e-07) p12 = -0.0004401 (-0.0007082, -0.0001721) p03 = 4.999 (4.082, 5.917)
plot(sf,[x,y],z)
fit a surface using variables in a matlab table
load the franke
data and convert it to a matlab® table.
load franke
t = table(x,y,z);
specify the variables in the table as inputs to the fit
function, and plot the fit.
f = fit([t.x, t.y],t.z,'linearinterp');
plot( f, [t.x, t.y], t.z )
create fit options and fit type before fitting
load and plot the data, create fit options and fit type using the fittype
and fitoptions
functions, then create and plot the fit.
load and plot the data in census.mat
.
load census plot(cdate,pop,'o')
create a fit options object and a fit type for the custom nonlinear model , where a and b are coefficients and n is a problem-dependent parameter.
fo = fitoptions('method','nonlinearleastsquares',... 'lower',[0,0],... 'upper',[inf,max(cdate)],... 'startpoint',[1 1]); ft = fittype('a*(x-b)^n','problem','n','options',fo);
fit the data using the fit options and a value of n = 2.
[curve2,gof2] = fit(cdate,pop,ft,'problem',2)
curve2 = general model: curve2(x) = a*(x-b)^n coefficients (with 95% confidence bounds): a = 0.006092 (0.005743, 0.006441) b = 1789 (1784, 1793) problem parameters: n = 2
gof2 = struct with fields:
sse: 246.1543
rsquare: 0.9980
dfe: 19
adjrsquare: 0.9979
rmse: 3.5994
fit the data using the fit options and a value of n = 3.
[curve3,gof3] = fit(cdate,pop,ft,'problem',3)
curve3 = general model: curve3(x) = a*(x-b)^n coefficients (with 95% confidence bounds): a = 1.359e-05 (1.245e-05, 1.474e-05) b = 1725 (1718, 1731) problem parameters: n = 3
gof3 = struct with fields:
sse: 232.0058
rsquare: 0.9981
dfe: 19
adjrsquare: 0.9980
rmse: 3.4944
plot the fit results with the data.
hold on plot(curve2,'m') plot(curve3,'c') legend('data','n=2','n=3') hold off
fit multiple polynomials
load the carbon12alpha
nuclear reaction sample data set.
load carbon12alpha
angle
is a vector of emission angles in radians. counts
is a vector of raw alpha particle counts that correspond to the angles in angle
.
display a scatter plot of the counts plotted against the angles.
scatter(angle,counts)
the scatter plot shows that the counts oscillate as the angle increases between 0
and 4.5
. to fit a polynomial model to the data, specify the fittype
input argument as "poly#"
where #
is an integer from one to nine. you can fit models of up to nine degrees. see for more information.
fit a fifth-degree, seventh-degree, and ninth-degree polynomial to the nuclear reaction data. return the goodness-of-fit statistics for each fit.
[f5,gof5] = fit(angle,counts,"poly5"); [f7,gof7] = fit(angle,counts,"poly7"); [f9,gof9] = fit(angle,counts,"poly9");
generate a vector of query points between 0
and 4.5
by using the function. evaluate the polynomial fits at the query points, and then plot them together with the nuclear reaction data.
xq = linspace(0,4.5,1000); figure hold on scatter(angle,counts,"k") plot(xq,f5(xq)) plot(xq,f7(xq)) plot(xq,f9(xq)) ylim([-100,550]) legend("original data","fifth-degree polynomial","seventh-degree polynomial","ninth-degree polynomial")
the plot indicates that the ninth-degree polynomial follows the data most closely.
display the goodness-of-fit statistics for each fit by using the function.
gof = struct2table([gof5 gof7 gof9],rownames=["f5" "f7" "f9"])
gof=3×5 table
sse rsquare dfe adjrsquare rmse
__________ _______ ___ __________ ______
f5 1.0901e 05 0.54614 18 0.42007 77.82
f7 32695 0.86387 16 0.80431 45.204
f9 3660.2 0.98476 14 0.97496 16.169
the sum-of-squares error (sse) for the ninth-degree polynomial fit is smaller than the sses for the fifth-degree and seventh-degree fits. this result confirms that the ninth-degree polynomial follows the data most closely.
fit a cubic polynomial specifying normalize and robust options
load some data and fit and plot a cubic polynomial with center and scale (normalize
) and robust fitting options.
load census; f=fit(cdate,pop,'poly3','normalize','on','robust','bisquare')
f = linear model poly3: f(x) = p1*x^3 p2*x^2 p3*x p4 where x is normalized by mean 1890 and std 62.05 coefficients (with 95% confidence bounds): p1 = -0.4619 (-1.895, 0.9707) p2 = 25.01 (23.79, 26.22) p3 = 77.03 (74.37, 79.7) p4 = 62.81 (61.26, 64.37)
plot(f,cdate,pop)
fit a curve defined by a file
define a function in a file and use it to create a fit type and fit a curve.
define a function in a matlab® file.
function y = piecewiseline(x,a,b,c,d,k) % piecewiseline a line made of two pieces % that is not continuous. y = zeros(size(x)); % this example includes a for-loop and if statement % purely for example purposes. for i = 1:length(x) if x(i) < k, y(i) = a b.* x(i); else y(i) = c d.* x(i); end end end
save the file.
define some data, create a fit type specifying the function
piecewiseline
, create a fit using the fit type
ft
, and plot the results.
x = [0.81;0.91;0.13;0.91;0.63;0.098;0.28;0.55;... 0.96;0.96;0.16;0.97;0.96]; y = [0.17;0.12;0.16;0.0035;0.37;0.082;0.34;0.56;... 0.15;-0.046;0.17;-0.091;-0.071]; ft = fittype( 'piecewiseline( x, a, b, c, d, k )' ) f = fit( x, y, ft, 'startpoint', [1, 0, 1, 0, 0.5] ) plot( f, x, y )
exclude points from fit
load some data and fit a custom equation specifying points to exclude. plot the results.
load data and define a custom equation and some start points.
[x, y] = titanium;
gausseqn = 'a*exp(-((x-b)/c)^2) d'
gausseqn = 'a*exp(-((x-b)/c)^2) d'
startpoints = [1.5 900 10 0.6]
startpoints = 1×4
1.5000 900.0000 10.0000 0.6000
create two fits using the custom equation and start points, and define two different sets of excluded points, using an index vector and an expression. use exclude
to remove outliers from your fit.
f1 = fit(x',y',gausseqn,'start', startpoints, 'exclude', [1 10 25])
f1 = general model: f1(x) = a*exp(-((x-b)/c)^2) d coefficients (with 95% confidence bounds): a = 1.493 (1.432, 1.554) b = 897.4 (896.5, 898.3) c = 27.9 (26.55, 29.25) d = 0.6519 (0.6367, 0.6672)
f2 = fit(x',y',gausseqn,'start', startpoints, 'exclude', x < 800)
f2 = general model: f2(x) = a*exp(-((x-b)/c)^2) d coefficients (with 95% confidence bounds): a = 1.494 (1.41, 1.578) b = 897.4 (896.2, 898.7) c = 28.15 (26.22, 30.09) d = 0.6466 (0.6169, 0.6764)
plot both fits.
plot(f1,x,y)
title('fit with data points 1, 10, and 25 excluded')
figure
plot(f2,x,y)
title('fit with data points excluded such that x < 800')
exclude points and plot fit showing excluded data
you can define the excluded points as variables before supplying them as inputs to the fit function. the following steps recreate the fits in the previous example and allow you to plot the excluded points as well as the data and the fit.
load data and define a custom equation and some start points.
[x, y] = titanium;
gausseqn = 'a*exp(-((x-b)/c)^2) d'
gausseqn = 'a*exp(-((x-b)/c)^2) d'
startpoints = [1.5 900 10 0.6]
startpoints = 1×4
1.5000 900.0000 10.0000 0.6000
define two sets of points to exclude, using an index vector and an expression.
exclude1 = [1 10 25]; exclude2 = x < 800;
create two fits using the custom equation, startpoints, and the two different excluded points.
f1 = fit(x',y',gausseqn,'start', startpoints, 'exclude', exclude1); f2 = fit(x',y',gausseqn,'start', startpoints, 'exclude', exclude2);
plot both fits and highlight the excluded data.
plot(f1,x,y,exclude1)
title('fit with data points 1, 10, and 25 excluded')
figure;
plot(f2,x,y,exclude2)
title('fit with data points excluded such that x < 800')
for a surface fitting example with excluded points, load some surface data and create and plot fits specifying excluded data.
load franke f1 = fit([x y],z,'poly23', 'exclude', [1 10 25]); f2 = fit([x y],z,'poly23', 'exclude', z > 1); figure plot(f1, [x y], z, 'exclude', [1 10 25]); title('fit with data points 1, 10, and 25 excluded')
figure plot(f2, [x y], z, 'exclude', z > 1); title('fit with data points excluded such that z > 1')
compare extrapolation methods
generate some noisy data using the membrane
and functions.
n = 41; m = membrane(1,20) 0.02*randn(n); [x,y] = meshgrid(1:n);
the matrix m
contains data for the l-shaped membrane with added noise. the matrices x
and y
contain the row and column index values, respectively, for the corresponding elements in m
.
display a surface plot of the data.
figure(1) surf(x,y,m)
the plot shows a wrinkled l-shaped membrane. the wrinkles in the membrane are caused by the noise in the data.
fit two surfaces through the wrinkled membrane using linear interpolation. for the first surface, specify the linear extrapolation method. for the second surface, specify the extrapolation method as nearest neighbor.
flinextrap = fit([x(:),y(:)],m(:),"linearinterp",extrapolationmethod="linear"); fnearextrap = fit([x(:),y(:)],m(:),"linearinterp",extrapolationmethod="nearest");
investigate the differences between the extrapolation methods by using the function to evaluate the fits at query points extending outside the convex hull of the x
and y
data.
[xq,yq] = meshgrid(-10:50); zlin = flinextrap(xq,yq); znear = fnearextrap(xq,yq);
plot the evaluated fits.
figure(2) surf(xq,yq,zlin) title("linear extrapolation") xlabel("x") ylabel("y") zlabel("m")
figure(3) surf(xq,yq,znear) title("nearest neighbor extrapolation") xlabel("x") ylabel("y") zlabel("m")
the linear extrapolation method generates spikes outside of the convex hull. the plane segments that form the spikes follow the gradient at points on the convex hull's border. the nearest neighbor extrapolation method uses the data on the border to extend the surface in each direction. this method of extrapolation generates waves that mimic the border.
fit a smoothing spline curve and return goodness-of-fit information
load some data and fit a smoothing spline curve through variables month
and pressure
, and return goodness of fit information and the output structure. plot the fit and the residuals against the data.
load enso; [curve, goodness, output] = fit(month,pressure,'smoothingspline'); plot(curve,month,pressure); xlabel('month'); ylabel('pressure');
plot the residuals against the x-data (month
).
plot( curve, month, pressure, 'residuals' ) xlabel( 'month' ) ylabel( 'residuals' )
use the data in the output
structure to plot the residuals against the y-data (pressure
).
plot( pressure, output.residuals, '.' ) xlabel( 'pressure' ) ylabel( 'residuals' )
fit a single-term exponential
generate data with an exponential trend, and then fit the data using the first equation in the curve fitting library of exponential models (a single-term exponential). plot the results.
x = (0:0.2:5)';
y = 2*exp(-0.2*x) 0.5*randn(size(x));
f = fit(x,y,'exp1');
plot(f,x,y)
fit a custom model using an anonymous function
you can use anonymous functions to make it easier to pass
other data into the fit
function.
load data and set emax
to 1
before defining your anonymous function:
data = importdata( 'opioidhypnoticsynergy.txt' );
propofol = data.data(:,1);
remifentanil = data.data(:,2);
algometry = data.data(:,3);
emax = 1;
define the model equation as an anonymous function:
effect = @(ic50a, ic50b, alpha, n, x, y) ... emax*( x/ic50a y/ic50b alpha*( x/ic50a )... .* ( y/ic50b ) ).^n ./(( x/ic50a y/ic50b ... alpha*( x/ic50a ) .* ( y/ic50b ) ).^n 1);
use the anonymous function effect
as an input to
the fit
function, and plot the results:
algometryeffect = fit( [propofol, remifentanil], algometry, effect, ... 'startpoint', [2, 10, 1, 0.8], ... 'lower', [-inf, -inf, -5, -inf], ... 'robust', 'lar' ) plot( algometryeffect, [propofol, remifentanil], algometry )
for more examples using anonymous functions and other custom models
for fitting, see the fittype
function.
find coefficient order to set start points and bounds
for the properties upper
, lower
, and startpoint
, you need to find the order of the entries for coefficients.
create a fit type.
ft = fittype('b*x^2 c*x a');
get the coefficient names and order using the coeffnames
function.
coeffnames(ft)
ans = 3x1 cell
{'a'}
{'b'}
{'c'}
note that this is different from the order of the coefficients in the expression used to create ft
with fittype
.
load data, create a fit and set the start points.
load enso fit(month,pressure,ft,'startpoint',[1,3,5])
ans = general model: ans(x) = b*x^2 c*x a coefficients (with 95% confidence bounds): a = 10.94 (9.362, 12.52) b = 0.0001677 (-7.985e-05, 0.0004153) c = -0.0224 (-0.06559, 0.02079)
this assigns initial values to the coefficients as follows: a = 1
, b = 3
, c = 5
.
alternatively, you can get the fit options and set start points and lower bounds, then refit using the new options.
options = fitoptions(ft)
options = nlsqoptions with properties: startpoint: [] lower: [] upper: [] algorithm: 'trust-region' diffminchange: 1.0000e-08 diffmaxchange: 0.1000 display: 'notify' maxfunevals: 600 maxiter: 400 tolfun: 1.0000e-06 tolx: 1.0000e-06 robust: 'off' normalize: 'off' exclude: [] weights: [] method: 'nonlinearleastsquares'
options.startpoint = [10 1 3]; options.lower = [0 -inf 0]; fit(month,pressure,ft,options)
ans = general model: ans(x) = b*x^2 c*x a coefficients (with 95% confidence bounds): a = 10.23 (9.448, 11.01) b = 4.335e-05 (-1.82e-05, 0.0001049) c = 5.523e-12 (fixed at bound)
input arguments
x
— data to fit
matrix
data to fit, specified as a matrix with either one (curve fitting) or
two (surface fitting) columns. you can specify variables in a
matlab table using tablename.varname
. cannot
contain inf
or nan
. only the real
parts of complex data are used in the fit.
example: x
example: [x,y]
data types: double
y
— data to fit
vector
data to fit, specified as a column vector with the same number of rows
as x
. you can specify a variable in a matlab table using tablename.varname
. cannot
contain inf
or nan
. only the real
parts of complex data are used in the fit.
use preparecurvedata
or
preparesurfacedata
if your data is not in
column vector form.
data types: double
z
— data to fit
vector
data to fit, specified as a column vector with the same number of rows
as x
. you can specify a variable in a matlab table using tablename.varname
. cannot
contain inf
or nan
. only the real
parts of complex data are used in the fit.
use preparesurfacedata
if your data is not in
column vector form. for example, if you have 3 matrices, or if your data
is in grid vector form, where length(x) = n, length(y) =
m
and size(z) = [m,n]
.
data types: double
fittype
— model type to fit
character vector | string scalar | string array | cell array of character vectors | anonymous function | fittype
model type to fit, specified as a character vector or string scalar
representing a library model name or matlab expression, a string array of linear model terms or a cell
array of character vectors of such terms, an anonymous function, or a
fittype
created with the function. you
can use any of the valid first inputs to fittype
as
an input to fit
.
for a list of library model names, see .
to a fit custom model, use a matlab expression, a cell array of linear model terms, or an
anonymous function. you can also create a fittype
using the fittype
function, and then use it as the
value of the fittype
input argument. for an
example, see fit a custom model using an anonymous function. for
examples that use linear model terms, see the
fittype
function.
example: "poly2"
fitoptions
— algorithm options
fitoptions
algorithm options constructed using the function. this is an alternative to specifying name-value pair arguments for fit options.
name-value arguments
specify optional pairs of arguments as
name1=value1,...,namen=valuen
, where name
is
the argument name and value
is the corresponding value.
name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
before r2021a, use commas to separate each name and value, and enclose
name
in quotes.
example: lower=[0,0],upper=[inf,max(x)],startpoint=[1 1]
specifies fitting method, bounds, and start points.
normalize
— option to center and scale data
'off'
(default) | 'on'
option to center and scale the data, specified as the
comma-separated pair consisting of 'normalize'
and 'on'
or 'off'
.
data types: char
exclude
— points to exclude from fit
expression | index vector | logical vector | empty
points to exclude from the fit, specified as the comma-separated
pair consisting of 'exclude'
and one of:
an expression describing a logical vector, e.g.,
x > 10
.a vector of integers indexing the points you want to exclude, e.g.,
[1 10 25]
.a logical vector for all data points where
true
represents an outlier, created by .
for an example, see exclude points from fit.
data types: logical
| double
problem
— values to assign to problem-dependent constants
cell array | double
values to assign to the problem-dependent constants, specified as
the comma-separated pair consisting of 'problem'
and a cell array with one element per problem dependent constant.
for details, see .
data types: cell
| double
smoothingparam
— smoothing parameter
scalar value in the range (0,1)
smoothing parameter, specified as the comma-separated pair
consisting of 'smoothingparam'
and a scalar value
between 0 and 1. the default value depends on the data set. only
available if the fit type is
smoothingspline
.
data types: double
span
— proportion of data points to use in local regressions
0.25 (default) | scalar value in the range (0,1)
proportion of data points to use in local regressions, specified
as the comma-separated pair consisting of 'span'
and a scalar value between 0 and 1. only available if the fit type
is lowess
or loess
.
data types: double
extrapolationmethod
— extrapolation method
"auto"
(default) | "none"
| "linear"
| "nearest"
| "thinplate"
| "biharmonic"
| "pchip"
| "cubic"
extrapolation method for an interpolant fit, specified as one of the following values:
value | description | supported fits |
---|---|---|
"auto" | default value for all interpolant fit
types. set
| all interpolant fit types and
|
"none" | no extrapolation. query points outside of
the convex hull of the fitting data evaluate to
|
|
"linear" | linear extrapolation based on boundary gradients.
|
|
"nearest" | nearest neighbor extrapolation. this extrapolation method evaluates to the value of the nearest point on the boundary of the fitting data's convex hull.
|
|
"thinplate" | thin-plate spline extrapolation. this extrapolation method extends the thin-plate interpolating spline outside of the fitting data's convex hull. for more information, see .
|
|
"biharmonic" | biharmonic spline extrapolation. this extrapolation method extends the biharmonic interpolating spline outside of the fitting data's convex hull.
|
|
"pchip" | piecewise cubic hermite interpolating polynomial (pchip) extrapolation. this extrapolation method extends a shape-preserving pchip outside of the fitting data's convex hull. for more information, see .
|
|
"cubic" | cubic spline extrapolation. this extrapolation method extends a cubic interpolating spline outside of the fitting data's convex hull.
|
|
data types: char
| string
robust
— robust linear least-squares fitting method
'off'
(default) | lar
| bisquare
robust linear least-squares fitting method, specified as the
comma-separated pair consisting of 'robust'
and
one of these values:
'lar'
specifies the least absolute residual method.'bisquare'
specifies the bisquare weights method.
available when the fit type
method
is
linearleastsquares
or
nonlinearleastsquares
.
data types: char
lower
— lower bounds on coefficients to be fitted
[ ] (default) | vector
lower bounds on the coefficients to be fitted, specified as the
comma-separated pair consisting of 'lower'
and a
vector. the default value is an empty vector, indicating that the
fit is unconstrained by lower bounds. if bounds are specified, the
vector length must equal the number of coefficients. find the order
of the entries for coefficients in the vector value by using the
function. for an example, see find coefficient order to set start points and bounds.
individual unconstrained lower bounds can be specified by
-inf
.
available when the method
is
linearleastsquares
or
nonlinearleastsquares
.
data types: double
upper
— upper bounds on coefficients to be fitted
[ ] (default) | vector
upper bounds on the coefficients to be fitted, specified as the
comma-separated pair consisting of 'upper'
and a
vector. the default value is an empty vector, indicating that the
fit is unconstrained by upper bounds. if bounds are specified, the
vector length must equal the number of coefficients. find the order
of the entries for coefficients in the vector value by using the
function. for an example, see find coefficient order to set start points and bounds.
individual unconstrained upper bounds can be specified by
inf
.
available when the method
is
linearleastsquares
or
nonlinearleastsquares
.
data types: logical
startpoint
— initial values for the coefficients
[ ] (default) | vector
initial values for the coefficients, specified as the
comma-separated pair consisting of 'startpoint'
and a vector. find the order of the entries for coefficients in the
vector value by using the
function. for an example, see find coefficient order to set start points and bounds.
if no start points (the default value of an empty vector) are
passed to the fit
function,
starting points for some library models are determined
heuristically. for rational and weibull models, and all custom
nonlinear models, the toolbox selects default initial values for
coefficients uniformly at random from the interval (0,1). as a
result, multiple fits using the same data and model might lead to
different fitted coefficients. to avoid this, specify initial values
for coefficients with a object
or a vector value for the startpoint
value.
available when the method
is
nonlinearleastsquares
.
data types: double
algorithm
— algorithm to use for fitting procedure
'trust-region' (default) | 'levenberg-marquardt'
algorithm to use for the fitting procedure, specified as the
comma-separated pair consisting of 'algorithm'
and either 'levenberg-marquardt'
or
'trust-region'
.
available when the method
is
nonlinearleastsquares
.
data types: char
diffmaxchange
— maximum change in coefficients for finite difference gradients
0.1 (default)
maximum change in coefficients for finite difference gradients,
specified as the comma-separated pair consisting of
'diffmaxchange'
and a scalar.
available when the method
is
nonlinearleastsquares
.
data types: double
diffminchange
— minimum change in coefficients for finite difference gradients
10–8 (default)
minimum change in coefficients for finite difference gradients,
specified as the comma-separated pair consisting of
'diffminchange'
and a scalar.
available when the method
is
nonlinearleastsquares
.
data types: double
display
— display option in command window
'notify'
(default) | 'final'
| 'iter'
| 'off'
display option in the command window, specified as the
comma-separated pair consisting of 'display'
and
one of these options:
'notify'
displays output only if the fit does not converge.'final'
displays only the final output.'iter'
displays output at each iteration.'off'
displays no output.
available when the method
is
nonlinearleastsquares
.
data types: char
maxfunevals
— maximum number of evaluations of model allowed
600
(default)
maximum number of evaluations of the model allowed, specified as
the comma-separated pair consisting of
'maxfunevals'
and a scalar.
available when the method
is
nonlinearleastsquares
.
data types: double
maxiter
— maximum number of iterations allowed for fit
400
(default)
maximum number of iterations allowed for the fit, specified as the
comma-separated pair consisting of 'maxiter'
and
a scalar.
available when the method
is
nonlinearleastsquares
.
data types: double
tolfun
— termination tolerance on model value
10–6 (default)
termination tolerance on the model value, specified as the
comma-separated pair consisting of 'tolfun'
and a
scalar.
available when the method
is
nonlinearleastsquares
.
data types: double
tolx
— termination tolerance on coefficient values
10–6 (default)
termination tolerance on the coefficient values, specified as the
comma-separated pair consisting of 'tolx'
and a
scalar.
available when the method
is
nonlinearleastsquares
.
data types: double
output arguments
fitobject
— fit result
cfit
| sfit
fit result, returned as a (for curves) or (for surfaces) object. see fit postprocessing for functions for plotting, evaluating, calculating confidence intervals, integrating, differentiating, or modifying your fit object.
gof
— goodness-of-fit statistics
gof
structure
goodness-of-fit statistics, returned as the gof
structure including the fields in this table.
field | value |
---|---|
| sum of squares due to error |
| r-squared (coefficient of determination) |
| degrees of freedom in the error |
| degree-of-freedom adjusted coefficient of determination |
| root mean squared error (standard error) |
output
— fitting algorithm information
output
structure
fitting algorithm information, returned as the
output
structure containing information
associated with the fitting algorithm.
fields depend on the algorithm. for example, the
output
structure for nonlinear least-squares
algorithms includes the fields shown in this table.
field | value |
---|---|
| number of observations (response values) |
| number of unknown parameters (coefficients) to fit |
| vector of residuals |
| jacobian matrix |
| describes the exit condition of the algorithm. positive flags indicate convergence, within tolerances. zero flags indicate that the maximum number of function evaluations or iterations was exceeded. negative flags indicate that the algorithm did not converge to a solution. |
| number of iterations |
| number of function evaluations |
| measure of first-order optimality (absolute maximum of gradient components) |
| fitting algorithm employed |
version history
introduced before r2006ar2023a: specify extrapolation method for surface interpolant fits
starting in 2023a, you can specify the extrapolation method for interpolant
fits by using the extrapolationmethod
name-value argument.
for curve fits, curve fitting toolbox™ supports only the default extrapolation methods available in
previous releases.
打开示例
您曾对此示例进行过修改。是否要打开带有您的编辑的示例?
matlab 命令
您点击的链接对应于以下 matlab 命令:
请在 matlab 命令行窗口中直接输入以执行命令。web 浏览器不支持 matlab 命令。
select a web site
choose a web site to get translated content where available and see local events and offers. based on your location, we recommend that you select: .
you can also select a web site from the following list:
how to get best site performance
select the china site (in chinese or english) for best site performance. other mathworks country sites are not optimized for visits from your location.
americas
- (español)
- (english)
- (english)
europe
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
asia pacific
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)