Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Evaluating Polynomials

The polyval function evaluates a polynomial at a specified value. To evaluate p at s = 5, use

polyval(p,5)

ans =
   110

It is also possible to evaluate a polynomial in a matrix sense. In this case p(x) = x3 – 2x – 5 becomes p(X ) = X 3 – 2X – 5I, where X is a square matrix and I is the identity matrix. For example, create a square matrix X and evaluate the polynomial p at X:

X = [2 4 5; -1 0 3; 7 1 5];
Y = polyvalm(p,X)

Y =
   377   179   439
   111    81   136
   490   253   639
Was this topic helpful?