Polynomials, like everything else in Matlab, is represented as a vector. The polynomial
3 3 x - 4 x + 5
is represented by the vector [3, 0, 4, 5].
Polynomial functions are:
Function | Comments | Example |
---|---|---|
conv | Compute the product of two polynomials | conv( [3 5 2], [3 0 0 2 3] ) |
deconv | Compute the quotient and remainder as a result of dividing the 1st polynomial by the 2nd | deconv( [3 0 0 2 3], [3 5 2] ) |
poly | Create a polynomial having the given roots | poly( [3 5 2 3] ) |
polyder | Differentiate the given polynomial | polyder( [3 5 2 3] ) |
polyval | Evaluate the polynomial at a point or points | polyval( [3 5 2 3], 3.235 ) |
polyvalm | Evaluate the polynomial at a matrix | polyvalm( [3 5 2 3], [1 2; 3 5] ) |
polyfit | Fit a polynomial to a set of points | polyfit( [1 2 3 5], [3 5 4 7], 3 ) |
roots | Find the roots of the given polynomial (including multiple roots.) | roots( [5 3 0 0 2] ) |
To evaluate the polynomial at a point, use the polyval function:
>> polyval( [3, 0, 4, 5], 3.2 ) ans = 116.1040 >> 3*3.2^3 + 4*3.2 + 5 ans = 116.1040
If the 2nd argument is a matrix, the polynomial is evaluated at each of the points. To evaluate 3*A^3 + 4*A + 3*eye(size(A)), see polyvalm.
To subsitute a matrix into a polynomial and evaluate it, use the polyvalm function:
>> A = [1 2; 3 4] >> polyvalm( [3, 0, 4, 5], [1 2; 3 4] ) ans = 120 170 255 375 >> 3*A^3 + 4*A + 5*eye(2) ans = 120 170 255 375