主要内容

评估表面拟合

此示例显示了如何与表面拟合一起工作。

Load Data and Fit a Polynomial Surface

load弗兰克; surffit = fit([x,y],z,'poly23','normalize','on')
线性模型poly23:surffit(x,y)= p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2 + p21*x^2*y + p12*x*x*y^2 + p03*y^3,其中x通过平均1982和std 868.6进行标准化,其中y通过平均0.4972和std 0.2897系数(置信度边界95%):p00 = 0.4253(0.4253(0.3928,0.4578)P10 = = 0.4578)P10 = = 0.4578)-0.106(-0.1322,-0.07974)p01 = -0.4299(-0.4775,-0.3822)p20 = 0.02104(0.001457,0.04062)(0.001372,0.04044)p12 = -0.0321(-0.05164,-0.01255)p03 = 0.1216(0.09929,0.1439)

The output displays the fitted model equation, the fitted coefficients, and the confidence bounds for the fitted coefficients.

Plot the Fit, Data, Residuals, and Prediction Bounds

plot(surffit,[x,y],z)

Figure contains an axes object. The axes object contains 2 objects of type surface, line.

Plot the residuals fit.

plot(surffit,[x,y],z,'Style','Residuals')

Figure contains an axes object. The axes object contains 2 objects of type patch, stem.

Plot prediction bounds on the fit.

plot(surffit,[x,y],z,'Style','predfunc')

Figure contains an axes object. The axes object contains 4 objects of type surface, line.

Evaluate the Fit at a Specified Point

Evaluate the fit at a specific point by specifying a value forxy,使用此表格:z = fittedModel(x,y).

Surffit(1000,0.5)
ans = 0.5673

Evaluate the Fit Values at Many Points

xi = [500;1000;1200]; yi = [0.7;0.6;0.5]; surffit(xi,yi)
ans =3×10.3771 0.4064 0.5331

Get prediction bounds on those values.

[ci, zi] = predint(surffit,[xi,yi])
ci =3×20.0713 0.6829 0.1058 0.7069 0.2333 0.8330
Zi =3×10.3771 0.4064 0.5331

得到模型方程

Enter the fit name to display the model equation, fitted coefficients, and confidence bounds for the fitted coefficients.

Surffit
线性模型poly23:surffit(x,y)= p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2 + p21*x^2*y + p12*x*x*y^2 + p03*y^3,其中x通过平均1982和std 868.6进行标准化,其中y通过平均0.4972和std 0.2897系数(置信度边界95%):p00 = 0.4253(0.4253(0.3928,0.4578)P10 = = 0.4578)P10 = = 0.4578)-0.106(-0.1322,-0.07974)p01 = -0.4299(-0.4775,-0.3822)p20 = 0.02104(0.001457,0.04062)(0.001372,0.04044)p12 = -0.0321(-0.05164,-0.01255)p03 = 0.1216(0.09929,0.1439)

To get only the model equation, useformula.

formula(surffit)
ans ='p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2 + p21*x^2*y + p12*x*x*y^2 + p03*y^3'

获取系数名称和值

Specify a coefficient by name.

p00 = surffit.p00
p00 = 0.4253
p03 = surffit.p03
p03 = 0.1216

Get all the coefficient names. Look at the fit equation (for example,f(x,y) = p00 + p10*x...) to see the model terms for each coefficient.

coeffnames(surffit)
ans =9x1 cell{'p00'} {'p10'} {'p01'} {'p20'} {'p11'} {'p02'} {'p21'} {'p12'} {'p03'}

获取所有系数值。

coeffvalues(surffit)
ans =1×90.4253 -0.1060 -0.4299 0.0210 0.0715 -0.0308 0.0209 -0.0321 0.1216

Get Confidence Bounds on the Coefficients

Use confidence bounds on coefficients to help you evaluate and compare fits. The confidence bounds on the coefficients determine their accuracy. Bounds that are far apart indicate uncertainty. If the bounds cross zero for linear coefficients, this means you cannot be sure that these coefficients differ from zero. If some model terms have coefficients of zero, then they are not helping with the fit.

confint(surffit)
ans =2×90.3928 -0.1322 -0.4775 0.0015 0.0541 -0.0504 0.0014-0.0516 0.0993 0.4578 -0.0797 -0.3822 0.0406 0.0406 0.016060.01130113 0113 0113 0.0113 0.0404-0404 -04-04-04-04-04-04-04-04-04-04-04-04-04-04-01126 0.1439

Find Methods

List every method that you can use with the fit.

methods(surffit)
Methods for class sfit: argnames dependnames indepnames predint sfit category differentiate islinear probnames type coeffnames feval numargs probvalues coeffvalues fitoptions numcoeffs quad2d confint formula plot setoptions

Use thehelp命令来找出如何use a fit method.

helpSFIT/QUAD2D
QUAD2D Numerically integrate a surface fit object. Q = QUAD2D(FO, A, B, C, D) approximates the integral of the surface fit object FO over the planar region A <= x <= B and C(x) <= y <= D(x). C and D may each be a scalar, a function handle or a curve fit (CFIT) object. [Q,ERRBND] = QUAD2D(...) also returns an approximate upper bound on the absolute error, ERRBND. [Q,ERRBND] = QUAD2D(FUN,A,B,C,D,PARAM1,VAL1,PARAM2,VAL2,...) performs the integration with specified values of optional parameters. See QUAD2D for details of the upper bound and the optional parameters. See also: QUAD2D, FIT, SFIT, CFIT.