polyval: Evaluating a Polynomial In pracma: Practical Numerical Math Functions

Description

Evaluate polynomial on vector or matrix.

Usage

 1 2 3 polyval(p, x) polyvalm(p, A)

Arguments

 p vector representing a polynomial. x vector of values where to evaluate the polynomial. A matrix; needs to be square.

Details

polyval valuates the polynomial given by p at the values specified by the elements of x. If x is a matrix, the polynomial will be evaluated at each element and a matrix returned.

polyvalm will evaluate the polynomial in the matrix sense, i.e., matrix multiplication is used instead of element by element multiplication as used in 'polyval'. The argument matrix A must be a square matrix.

Value

Vector of values, resp. a matrix.

Examples

 1 2 3 4 5 6 7 8 # Evaluate 3 x^2 + 2 x + 1 at x = 5, 7, and 9 p = c(3, 2, 1); polyval(p, c(5, 7, 9)) # 86 162 262 # Apply the characteristic polynomial to its matrix A <- pascal(4) p <- pracma::Poly(A) # characteristic polynomial of A polyvalm(p, A) # almost zero 4x4-matrix

Example output

  86 162 262
[,1]         [,2]         [,3]         [,4]
[1,] 2.715272e-12 9.574563e-12 2.215472e-11 4.222400e-11
[2,] 9.695356e-12 3.281742e-11 7.533174e-11 1.424922e-10
[3,] 2.220801e-11 7.457501e-11 1.699593e-10 3.207958e-10
[4,] 4.180478e-11 1.393836e-10 3.171046e-10 5.975781e-10

pracma documentation built on Dec. 11, 2021, 9:57 a.m.