# root

Represent roots of polynomial

## Syntax

``root(p,x)``
``root(p,x,k)``

## Description

example

````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 or mathematically impossible. In this case, the Symbolic Math Toolbox™ uses the `root` function to represent the roots of the polynomial.```

example

````root(p,x,k)` represents the `k`th root of symbolic polynomial `p` with respect to `x`.```

## Examples

### Represent Roots of High-Degree Polynomial

Represent the roots of the polynomial ${x}^{3}+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(x^3 + 1, x, 1) root(x^3 + 1, x, 2) root(x^3 + 1, x, 3)```

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

### Find Roots of High-Degree Polynomial

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(z^3 + 3*z - 16, z, 1) root(z^3 + 3*z - 16, z, 2) root(z^3 + 3*z - 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 = (65^(1/2) + 8)^(1/3) - 1/(65^(1/2) + 8)^(1/3) 1/(2*(65^(1/2) + 8)^(1/3)) - (65^(1/2) + 8)^(1/3)/2 -... (3^(1/2)*(1/(65^(1/2) + 8)^(1/3) + (65^(1/2) + 8)^(1/3))*1i)/2 1/(2*(65^(1/2) + 8)^(1/3)) - (65^(1/2) + 8)^(1/3)/2 +... (3^(1/2)*(1/(65^(1/2) + 8)^(1/3) + (65^(1/2) + 8)^(1/3))*1i)/2```

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

`Rnumeric = vpa(R)`
```RRnumeric = 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`.

### Use `root` in Symbolic Computations

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(x^2 + 5*x, 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(b^2*x^2 + b^2*x, x, 1)```

### Find Inverse Laplace Transform of Ratio of Polynomials

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 - symsum(exp(t*root(s3^4 + s3^3 + 1, s3, k))/... (4*root(s3^4 + s3^3 + 1, s3, k) + 3), k, 1, 4)```

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.30881178580997278695808136329347*exp(-1.0189127943851558447865795886366*t)*... cos(0.60256541999859902604398442197193*t) -... 0.30881178580997278695808136329347*exp(0.5189127943851558447865795886366*t)*... cos(0.666609844932018579153758800733*t) -... 0.6919689479355443779463355813596*exp(-1.0189127943851558447865795886366*t)*... sin(0.60256541999859902604398442197193*t) -... 0.16223098826244593894459034019473*exp(0.5189127943851558447865795886366*t)*... sin(0.666609844932018579153758800733*t)```

## 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`.