<< numrows Robotics_Toolbox r2t >>

Robotics_Toolbox >> Robotics_Toolbox > polyval

polyval

Polynomial evaluation

Calling Sequence

y = polyval(p,x)
y = polyval(p,x,S)
[y,delta] = polyval(p,x,S)

Parameters

p :

a (n+1)-by-1 matrix of doubles, the coefficients of the polynomial, with powers in decreasing order

x :

a nx-by-my matrix of doubles, the points where to evaluate the polynomial

S :

the optional data structure from polyfit

y :

a nx-by-my matrix of doubles, the value of the polynomial at x

delta :

Description

If p is a vector of length n+1 whose elements are the coefficients of a polynomial, then y=polyval(p,x) is the value of the polynomial, defined by its coefficients p, evaluated at x.

These coefficients are ordered with powers in decreasing order:

p(x) = p_1 x^n + p_2 x^{n-1} + ... + p_n x + p_{n+1}.

If x is a matrix, the polynomial is evaluated at all points in x.

[y,delta] = polyval(p,x,S) uses the optional output generated by polyfit to generate error estimates, y+/-delta.

Examples

p=[3 2 1];
y=polyval(p,[5 7 9])
expected=[86 162 262]

// Evaluate for x matrix
x = linspace(0,%pi,10);
y = sin(x);
p = polyfit(x,y,3);
// Evaluate at x matrix
x = linspace(0,%pi,12);
x=matrix(x,3,4)
f=polyval(p,x)
y=sin(x)

// Evaluate 95% confidence bounds,
// i.e. +/- 2*delta
// Source: [1,2]
cdate=(1790:10:1990)';
pop=[
3.929214
5.308483
7.239881
9.638453
12.860702
17.063353
23.191876
31.443321
38.558371
50.189209
62.979766
76.212168
92.228496
106.02154
123.20262
132.16457
151.3258
179.32317
203.30203
226.5422
248.70987
];
scf();
plot(cdate,pop,"+")
// Calculate fit parameters
[p,S] = polyfit(cdate,pop,2);
// Evaluate the fit and the prediction error estimate (delta)
[pop_fit,delta] = polyval(p,cdate,S);
// Plot the data, the fit, and the confidence bounds
plot(cdate,pop_fit,"g-")
plot(cdate,pop_fit+2*delta,"r:")
plot(cdate,pop_fit-2*delta,"r:")
// Annotate the plot
xlabel("Census Year");
ylabel("Population (millions)");
title("Quadratic Polynomial Fit with Confidence Bounds")

Authors

Bibliography

[1] http://en.wikipedia.org/wiki/Polynomial_interpolation

[2] http://www.mathworks.fr/fr/help/matlab/data_analysis/programmatic-fitting.html

[3] Numerical Computing with MATLAB, Cleve Moler, 2004


Report an issue
<< numrows Robotics_Toolbox r2t >>