symbolic toolbox roots in matlab

To find the roots of a polynomial using the symbolic toolbox in MATLAB, you can follow these steps:

  1. Define the polynomial as a symbolic expression using the sym function:
main.m
syms x
p = sym('2*x^3 + 3*x^2 - 2*x - 1');
43 chars
3 lines
  1. Use the roots function to find the roots of the polynomial:
main.m
r = roots(p);
14 chars
2 lines

The roots function returns a column vector containing the roots of the polynomial.

Here's an example code block that puts these steps together:

main.m
syms x
p = sym('2*x^3 + 3*x^2 - 2*x - 1');
r = roots(p);
disp(r);
66 chars
5 lines

When you run this code, you'll get the following output:

main.m
-0.8944
 0.2605
-0.1341
24 chars
4 lines

The roots function can also be used to find the roots of a system of equations. In that case, you would pass the system of equations as a vector of symbolic expressions to the roots function.

gistlibby LogSnag