Main Content

polyval

多项式评估

Description

例子

y= polyVal(p,,,,X评估多项式p在每个点X。论点p是a vector of lengthn+1whose elements are the coefficients (in descending powers) of annth级多项式:

p (( X = p 1 X n + p 2 X n - 1 + 。。。 + p n X + p n + 1

的polynomial coefficients inpcan be calculated for different purposes by functions likepolyint,,,,聚生, 和polyfit,但是您可以为系数指定任何向量。

要评估矩阵的多项式,请使用polyvalm反而。

例子

[[y,,,,三角洲] = polyval(p,,,,X,,,,suses the optional output structures由。。。生产polyfitto generate error estimates.三角洲是an estimate of the standard error in predicting a future observation atX经过p((X)

例子

y= polyVal(p,,,,X,[],,或者[[y,,,,三角洲] = polyval(p,,,,X,,,,s,,,,使用可选输出由。。。生产polyfit中心和扩展数据。亩((1)平均(x), 和亩((2)std(x)。Using these values,polyval中心Xat zero and scales it to have unit standard deviation,

X ^ = X - X σ X

This centering and scaling transformation improves the numerical properties of the polynomial.

Examples

全部收缩

Evaluate the polynomial p (( X = 3 X 2 + 2 X + 1 at the points X = 5 ,,,, 7 ,,,, 9 。多项式系数可以由矢量表示[[321]

p = [3 2 1];x = [5 7 9];y = polyval(p,x)
y=1×386 162 262

评估确定的积分

= - 1 3 (( 3 X 4 - 4 X 2 + 1 0 X - 2 5 d X

Create a vector to represent the polynomial integrand 3 X 4 - 4 X 2 + 1 0 X - 2 5 。的 X 3 term is absent and thus has a coefficient of 0.

p=[[30-410-25];

利用polyintto integrate the polynomial using a constant of integration equal to0

Q =polyint((p)
Q =1×60。6000 0 -1.3333 5.0000 -25.0000 0

Find the value of the integral by evaluating在整合的范围内。

a = -1;b = 3;i = diff(polyval(q,[a b]))
i = 49.0667

Fit a linear model to a set of data points and plot the results, including an estimate of a 95% prediction interval.

Create a few vectors of sample data points((X,,,,y)。利用polyfit为了将第一度多项式拟合到数据。指定两个输出以返回线性拟合以及误差估计结构的系数。

x = 1:100;y = -0.3*x + 2*randn(1,100);[p,s] = polyFit(x,y,1);

评估一级多项式拟合pX。将误差估计结构指定为第三个输入,以便polyval计算估计的标准误差。的standard error estimate is returned in三角洲

[y_fit,delta] = polyval(p,x,s);

Plot the original data, linear fit, and 95% prediction interval y ± 2 Δ

情节(x,y,'bo') 抓住情节(x,y_fit,'r-')plot(x,y_fit+2*delta,'M--',x,y_fit-2*delta,'M--')title('Linear Fit of Data with 95% Prediction Interval')legend('Data',,,,“线性拟合”,,,,'95%的预测间隔'

图包含一个轴对象。的axes object with title Linear Fit of Data with 95% Prediction Interval contains 4 objects of type line. These objects represent Data, Linear Fit, 95% Prediction Interval.

Create a table of population data for the years 1750 - 2000 and plot the data points.

年=((1750:25:2000)'; pop = 1e6*[791 856 978 1050 1262 1544 1650 2532 6122 8170 11560]'; T = table(year, pop)
T=11×2桌年pop ____ _________ 1750 7.91e+08 1775 8.56e+08 1800 9.78e+08 1825 1.05e+09 1850 1.262e+09 1875 1.544e+09 1900 1.65e+09 1925 2.532e+09 1950 6.122e+09 1975 8.17e+09 2000 1.156e+10
plot(year,pop,'o'

图包含一个轴对象。轴对象包含一个类型行的对象。

利用polyfitwith three outputs to fit a 5th-degree polynomial using centering and scaling, which improves the numerical properties of the problem.polyfit中心数据at 0 and scales it to have a standard deviation of 1, which avoids an ill-conditioned Vandermonde matrix in the fit calculation.

[p,〜,mu] = polyFit(t.year,t.pop,5);

利用polyval有四个输入来评估p随着时间的扩展,(Year-mu(1))/MU(2)。将结果与原始年份相对。

f = polyVal(p,Year,[],Mu);抓住情节(年,f)持有离开

图包含一个轴对象。轴对象包含2个类型行的对象。

输入参数

全部收缩

多项式系数,,,,specified as a vector. For example, the vector[1 0 1]代表多项式 X 2 + 1 和矢量[[3.13-2。215。99]代表多项式 3.13 X 2 - 2.21 X + 5。99

有关更多信息,请参阅Create and Evaluate Polynomials

Data Types:single|double
复杂的数字支持:万博1manbetxYes

查询点,,,,specified as a vector.polyval评估多项式pX并返回相应的函数值y

Data Types:single|double
复杂的数字支持:万博1manbetxYes

误差估计结构。该结构是从[[p,,,,s] = polyfit(x,y,n)that can be used to obtain error estimates.s包含以下字段:

场地 Description
r Triangular factor from a QR decomposition of the Vandermonde matrix ofX
DF Degrees of freedom
n或者mr Norm of the residuals

如果the data iny是随机的,然后是对协方差矩阵的估计p((rinv*Rinv')*normr^2/df,,,,whererinv是the inverse ofr

中心和缩放值,指定为两元素向量。该向量是来自[[p,,,,s,,,,亩] = polyfit(x,y,n)that is used to improve the numerical properties of fitting and evaluating the polynomialp。的value亩((1)平均(x), 和亩((2)std(x)。的se values are used to center the query points inXat zero with unit standard deviation.

specify评估p在缩放点,(x -mu(1))/mu(2)

Output Arguments

全部收缩

功能值,作为与查询点相同大小的向量返回X。矢量包含评估多项式的​​结果p在每个点X

预测的标准错误,作为与查询点相同大小的向量返回X。Generally, an interval ofy±Δ对应于大约68%的预测间隔,以将来观察到大型样本,以及y±2Δ大约95%的预测间隔。

如果系数在p是由polyfit, 和the errors in the data input topolyfitare independent, normal, and have constant variance, theny±Δ至少是50%的预测间隔。

Extended Capabilities

C/C++ Code Generation
使用MATLAB®CODER™生成C和C ++代码。

版本历史记录

在R2006a之前引入