Main Content

root

Represent roots of polynomial

Description

r = root(p,x) returns a column vector of numbered roots of symbolic polynomial p with respect to x. Symbolically solving a high-degree polynomial for its roots can be complex and not all polynomials can be solved analytically. In this case, the Symbolic Math Toolbox™ uses the root function to represent the roots of the polynomial.

example

r = root(p,x,k) represents the kth root of symbolic polynomial p with respect to x.

example

Examples

collapse all

Represent the roots of the polynomial x3+1 using root. The root function returns a column vector. The elements of this vector represent the three roots of the polynomial.

syms x
p = x^3 + 1;
root(p,x)
ans = 

(root(x3+1,x,1)root(x3+1,x,2)root(x3+1,x,3))

root(x3+1,x,1) represents the first root of p, while root(x3+1,x,2) represents the second root, and so on. Use this syntax to represent roots of high-degree polynomials.

Find the roots of the quadratic polynomial x2-x-1. You can use the root function to represent these roots.

syms x
p = x^2 - x - 1;
r = root(p,x)
r = 

(root(x2-x-1,x,1)root(x2-x-1,x,2))

To convert these roots to high-precision floating point numbers, you can use vpa.

rVpa = vpa(r)
rVpa = 

(-0.618033988749894848204586834365641.6180339887498948482045868343656)

When solving a high-degree polynomial, solve represents the roots by using root. Alternatively, you can either return an explicit solution by using the MaxDegree option or return a numerical result by using vpa.

Find the roots of x^3 + 3*x - 16.

syms x
p = x^3 + 3*x - 16;
R = solve(p,x)
R = 

(root(z3+3z-16,z,1)root(z3+3z-16,z,2)root(z3+3z-16,z,3))

Find the roots explicitly by setting the MaxDegree option to the degree of the polynomial. Polynomials with a degree greater than 4 do not have explicit solutions.

Rexplicit = solve(p,x,"MaxDegree",3)
Rexplicit = 

(σ1-1σ112σ1-σ12-31σ1+σ1i212σ1-σ12+31σ1+σ1i2)where  σ1=65+81/3

Calculate the roots numerically by using vpa to convert R to high-precision floating point.

Rnumeric = vpa(R)
Rnumeric = 

(2.1267693318103912337456401562601-1.0633846659051956168728200781301-2.5283118563671914055545884653776i-1.0633846659051956168728200781301+2.5283118563671914055545884653776i)

If the call to root contains parameters, substitute the parameters with numbers by using subs before calling vpa.

You can use the root function as input to Symbolic Math Toolbox functions such as simplify, subs, and diff.

Simplify an expression containing root using the simplify function.

syms x
r = root(x^6 + x, x, 1);
simplify(sin(r)^2 + cos(r)^2)
ans = 1

Substitute for parameters in root with numbers using subs.

syms b
subs(root(x^2 + b*x, x, 1), b, 5)
ans = root(x2+5x,x,1)

Substituting for parameters using subs is necessary before converting root to numeric form using vpa.

Differentiate an expression containing root with respect to a parameter using diff.

diff(root(x^2 + b*x, x, 1), b)
ans = 

root(x2+bx,x,1)b

Find the inverse Laplace transform of a ratio of two polynomials using ilaplace. The inverse Laplace transform is returned in terms of root.

syms s
G = (s^3 + 1)/(s^6 + s^5 + s^2);
H = ilaplace(G)
H = 

t-k=14etroot(z4+z3+1,z,k)4root(z4+z3+1,z,k)+3

When you get the root function in output, you can use the root function as input in subsequent symbolic calculations. However, if a numerical result is required, convert the root function to a high-precision numeric result using vpa.

Convert the inverse Laplace transform to numeric form using vpa.

H_vpa = simplify(vpa(H))
H_vpa = t+0.30881178580997278695808136329347e-1.0189127943851558447865795886366tcos(0.60256541999859902604398442197193t)-0.30881178580997278695808136329347e0.5189127943851558447865795886366tcos(0.666609844932018579153758800733t)-0.6919689479355443779463355813596e-1.0189127943851558447865795886366tsin(0.60256541999859902604398442197193t)-0.16223098826244593894459034019473e0.5189127943851558447865795886366tsin(0.666609844932018579153758800733t)

Input Arguments

collapse all

Symbolic polynomial, specified as a symbolic expression.

Variable, specified as a symbolic variable.

Number of polynomial root, specified as a number, vector, matrix, multidimensional array, or a symbolic number, vector, matrix, or multidimensional array. When k is a nonscalar, root acts element-wise on k.

Example: root(f,x,3) represents the third root of f.

Tips

  • You can numerically approximate a symbolic expression involving the root function by using vpa to return variable-precision symbolic numbers. Starting in R2023a, you can convert the expression to a MATLAB® function that can be used without Symbolic Math Toolbox by using matlabFunction. The generated file uses the roots function that operates on the numeric double data type.

Version History

Introduced in R2015b

See Also

| |