find the roots of a polynomial in matlab

To find the roots of a polynomial in MATLAB, you can simply use the roots function. This function takes a vector of polynomial coefficients and returns the roots of the polynomial.

Here's the general syntax:

main.m
roots_vector = roots(coefficients_vector)
42 chars
2 lines

For example, let's say you have a polynomial x^2 - 4x + 4. The coefficient vector would be [1, -4, 4]. To find the roots of this polynomial, you would do the following:

main.m
coefficients_vector = [1, -4, 4];
roots_vector = roots(coefficients_vector);
77 chars
3 lines

The roots_vector would then contain the values [2, 2], which are the roots of the polynomial.

It's important to note that the roots function works for both real and complex roots, and that the output will always be a column vector containing all the roots.

gistlibby LogSnag