Next: Control Theory, Previous: Sets, Up: Top

In Octave, a polynomial is represented by its coefficients (arranged
in descending order). For example, a vector
$c$
of length
`N`

p(x) =c(1) x^N+ ... +c(N) x +c(N+1).

— Function File: **compan** (`c`)

Compute the companion matrix corresponding to polynomial coefficient vector

c.The companion matrix is

_ _ | -c(2)/c(1) -c(3)/c(1) ... -c(N)/c(1) -c(N+1)/c(1) | | 1 0 ... 0 0 | | 0 1 ... 0 0 | A = | . . . . . | | . . . . . | | . . . . . | |_ 0 0 ... 1 0 _|The eigenvalues of the companion matrix are equal to the roots of the polynomial.

— Function File: **conv** (`a, b`)

Convolve two vectors.

`y = conv (a, b)`

returns a vector of length equal to`length (a) + length (b) - 1`

. Ifaandbare polynomial coefficient vectors,`conv`

returns the coefficients of the product polynomial.

— Function File: **deconv** (`y, a`)

Deconvolve two vectors.

`[b, r] = deconv (y, a)`

solves forbandrsuch that`y = conv (a, b) + r`

.If

yandaare polynomial coefficient vectors,bwill contain the coefficients of the polynomial quotient andrwill be a remander polynomial of lowest order.

— Function File: **poly** (`a`)

If

ais a square N-by-N matrix,`poly (`

a`)`

is the row vector of the coefficients of`det (z * eye (N) - a)`

, the characteristic polynomial ofa. Ifxis a vector,`poly (`

x`)`

is a vector of coefficients of the polynomial whose roots are the elements ofx.

— Function File: **polyderiv** (`c`)

Return the coefficients of the derivative of the polynomial whose coefficients are given by vector

c.

— Function File: [`p`, `s`] = **polyfit** (`x, y, n`)

Return the coefficients of a polynomial

p(x) of degreenthat minimizes`sumsq (p(x(i)) - y(i))`

, to best fit the data in the least squares sense.The polynomial coefficients are returned in a row vector.

If two output arguments are requested, the second is a structure containing the following fields:

`R`

- The Cholesky factor of the Vandermonde matrix used to compute the polynomial coefficients.
`X`

- The Vandermonde matrix used to compute the polynomial coefficients.
`df`

- The degrees of freedom.
`normr`

- The norm of the residuals.
`yf`

- The values of the polynomial for each value of
x.

— Function File: **polyinteg** (`c`)

Return the coefficients of the integral of the polynomial whose coefficients are represented by the vector

c.The constant of integration is set to zero.

— Function File: **polyreduce** (`c`)

Reduces a polynomial coefficient vector to a minimum number of terms by stripping off any leading zeros.

— Function File: **polyval** (`c, x`)

Evaluate a polynomial.

`polyval (`

c`,`

x`)`

will evaluate the polynomial at the specified value ofx.If

xis a vector or matrix, the polynomial is evaluated at each of the elements ofx.

— Function File: **polyvalm** (`c, x`)

Evaluate a polynomial in the matrix sense.

`polyvalm (`

c`,`

x`)`

will evaluate the polynomial in the matrix sense, i.e. matrix multiplication is used instead of element by element multiplication as is used in polyval.The argument

xmust be a square matrix.

— Function File: **residue** (`b, a, tol`)

If

bandaare vectors of polynomial coefficients, then residue calculates the partial fraction expansion corresponding to the ratio of the two polynomials. The function`residue`

returnsr,p,k, ande, where the vectorrcontains the residue terms,pcontains the pole values,kcontains the coefficients of a direct polynomial term (if it exists) andeis a vector containing the powers of the denominators in the partial fraction terms.Assuming

bandarepresent polynomials P (s) and Q(s) we have:P(s) M r(m) N ---- = SUM ------------- + SUM k(i)*s^(N-i) Q(s) m=1 (s-p(m))^e(m) i=1where M is the number of poles (the length of the

r,p, andevectors) and N is the length of thekvector.The argument

tolis optional, and if not specified, a default value of 0.001 is assumed. The tolerance value is used to determine whether poles with small imaginary components are declared real. It is also used to determine if two poles are distinct. If the ratio of the imaginary part of a pole to the real part is less thantol, the imaginary part is discarded. If two poles are farther apart thantolthey are distinct. For example,b = [1, 1, 1]; a = [1, -5, 8, -4]; [r, p, k, e] = residue (b, a); => r = [-2, 7, 3] => p = [2, 2, 1] => k = [](0x0) => e = [1, 2, 1]which implies the following partial fraction expansion

s^2 + s + 1 -2 7 3 ------------------- = ----- + ------- + ----- s^3 - 5s^2 + 8s - 4 (s-2) (s-2)^2 (s-1)