Matlab provides several built-in functions to find the roots of a given polynomial equation.
One of the functions that can be used to find the roots of a polynomial is roots()
.
Here is the general syntax:
main.m15 chars2 lines
where polyVec
is a vector containing the coefficients of the polynomial in decreasing order. For example,
main.m16 chars2 lines
represents the polynomial 3x^3 + 4x^2 - 1
.
To find the roots of this polynomial, we can use the roots()
function as follows:
main.m13 chars2 lines
The result would be:
main.m38 chars6 lines
These values represent the roots of the polynomial.
Another function that can be used to find the roots of a polynomial is polyval()
. This function evaluates the polynomial for a given input and can be used to confirm whether a particular value is a root of the polynomial.
Here is an example usage of polyval()
:
main.m25 chars3 lines
Output:
main.m12 chars4 lines
Since the value of y
is not zero, we can determine that x=1
is not a root of the polynomial.
gistlibby LogSnag