# poly

Polynomial definition from given roots or coefficients, or characteristic to a square matrix.

### Syntax

p = poly(vec, vname) p = poly(vec, vname, "roots"|"coeff") Pc = poly(matNN, vname)

### Arguments

- vname
a string: the symbolic variable name of the polynomial. Allowed characters are the same as for variables names (see naming rules).

- vec
scalar, vector, or non-square matrix of real or complex numbers.

- flag "roots" (default) | "coeff" (or "r" | "c")
Indicates what numbers in

`vec`

represent.`"roots"`

is the default value.Shortcuts can be used:

`"r"`

for`"roots"`

, and`"c"`

for`"coeff"`

.- p
Polynomial with given roots or coefficients and symbolic variable name.

- matNN
Square matrix of real or complex numbers.

- Pc
Characteristic polynomial of the given square matrix, =

`det(x*eye() - matNN)`

, with the symbolic variable`x = poly(0,vname)`

.

### Description

- When a vector or non-square matrix
`vec`

is provided, `p = poly(vec, "x", "roots")`

or`p = poly(vec, "x")`

is the polynomial whose roots are the`vec`

components, and`"x"`

is the name of its variable.`degree(p)==length(vec)`

`poly()`

and`roots()`

are then inverse functions of each other.- Infinite roots give null highest degree coefficients.
In this case, the actual degree of
`p`

is smaller than`length(vec)`

. For instance,`poly([-%inf -1 2 %inf ], "x")`

yields`(x-2)(x+1)`

whose degree is 2.

The simple expression

`x=poly(0,"x")`

defines the elementary`p(x)=x`

, which then can be used with usual operators +, -, *, / and simple functions like`sum()`

.Scilab provides 3 predefined elementary polynomials`%s`

,`%z`

, and`$`

. The last one is mainly used as symbolic value of last index (of a range).`poly(vec, "x", "coeff")`

builds the polynomial with symbol`"x"`

whose coefficients in order of increasing degree are`vec`

components (`vec(1)`

is the constant term of the polynomial). Null high order coefficients (appended to`vec`

) are ignored.Conversely,`coeff(p)`

returns the coefficients of a given polynomial.

- When a square matrix
`matNN`

is provided, `poly(matNN, vname)`

returns its characteristic polynomial of symbolic variable`vname`

, i.e.`p`

is set to`det(x*eye() - matNN)`

, with`x = poly(0,vname)`

.

### Examples

Building a polynomial of given coefficients:

// Direct building: x = poly(0, "x"); p = 1 - x + 2*x^3 // With poly(): p2 = poly([1 -1 0 2], "x", "coeff") // With null high order coefficients p3 = poly([2 0 -3 zeros(1,8)], "y", "coeff")

--> p = 1 - x + 2*x^3 p = 3 1 -x +2x --> p2 = poly([1 -1 0 2], "x", "coeff") p2 = 3 1 -x +2x --> p3 = poly([2 0 -3 zeros(1,8)], "y", "coeff") p3 = 2 2 -3y

Building a polynomial of given roots:

// Direct building: x = poly(0,"x"); p = (1-x)^2 * (2+x) // With poly(): p2 = poly([1 1 -2], "x") // With infinite roots p3 = poly([%inf -1 2 %inf -%inf], "x")

--> p = (1-x)^2 * (2+x) p = 3 2 -3x +x --> p2 = poly([1 1 -2], "x") p2 = 3 2 -3x +x --> p3 = poly([%inf -1 2 %inf -%inf], "x") p3 = 2 -2 -x +x

Characteristic polynomial of a square matrix:

A = [1 2 ; 3 -4] poly(A, "x")

--> A = [1 2 ; 3 -4] A = 1. 2. 3. -4. --> poly(A, "x") ans = 2 -10 +3x +x

### See also

### History

Version | Description |

5.5.0 | The only values allowed for the third argument are "roots", "coeff", "c" and "r". |

6.0.0 | The name of the symbolic variable is no longer limited to 4 characters. It can include some extended UTF-8 characters. |

6.0.2 | With the "coeff" method, null high order coefficients are now ignored. |

## Comments

Add a comment:Please login to comment this page.