view doc/interpreter/poly.texi @ 2342:95e511896bf5

[project @ 1996-07-24 18:05:43 by jwe]
author jwe
date Wed, 24 Jul 1996 18:08:39 +0000
parents b1a56412c385
children 31d5588dbb61
line wrap: on
line source

@c Copyright (C) 1996 John W. Eaton
@c This is part of the Octave manual.
@c For copying conditions, see the file gpl.texi.

@node Polynomial Manipulations, Nonlinear Equations, Linear Algebra, Top
@chapter Polynomial Manipulations

In Octave, a polynomial is represented by its coefficients (arranged
in descending order).  For example, a vector @var{c} of length @var{n+1}
corresponds to the following @var{n}-th order polynomial
@iftex
@tex
$$
 p (x) = c_1 x^n + ... + c_n x + c_{n+1}.
$$
@end tex
@end iftex
@ifinfo

@example
p(x) = c(1) x^n + ... + c(n) x + c(n+1).
@end example
@end ifinfo

@ftable @code
@item compan (@var{c})
Compute the companion matrix corresponding to polynomial coefficient
vector @var{c}.

The companion matrix is
@iftex
@tex
$$
A = \left[\matrix{
 -c_2/c_1 & -c_3/c_1 & \cdots & -c_n/c_1 & -c_{n+1}/c_1\cr  
     1    &     0    & \cdots &     0    &         0   \cr
     0    &     1    & \cdots &     0    &         0   \cr
  \vdots  &          & \ddots &  \vdots  &      \vdots \cr
     0    &     0    & \cdots &     1    &         0}\right].
$$
@end tex
@end iftex
@ifinfo

@smallexample
     _                                                        _
    |  -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     _|
@end smallexample
@end ifinfo

The eigenvalues of the companion matrix are equal to the roots of the
polynomial.

@item conv (@var{a}, @var{b})
Convolve two vectors.

@code{y = conv (a, b)} returns a vector of length equal to
@code{length (a) + length (b) - 1}.
If @var{a} and @var{b} are polynomial coefficient vectors, @code{conv}
returns the coefficients of the product polynomial.

@item deconv (@var{y}, @var{a})
Deconvolve two vectors.

@code{[b, r] = deconv (y, a)} solves for @var{b} and @var{r} such that
@code{y = conv (a, b) + r}.

If @var{y} and @var{a} are polynomial coefficient vectors, @var{b} will
contain the coefficients of the polynomial quotient and @var{r} will be
a remander polynomial of lowest order.

@item poly (@var{a})
If @var{a} is a square @var{n}-by-@var{n} matrix, @code{poly (@var{a})}
is the row vector of the coefficients of @code{det (z * eye (n) - a)},
the characteristic polynomial of @var{a}.  If @var{x} is a vector,
@code{poly (@var{x})} is a vector of coefficients of the polynomial
whose roots are the elements of @var{x}.

@item polyderiv (@var{c})
Returns the coefficients of the derivative of the polynomial whose
coefficients are given by vector @var{c}.

@item polyinteg (@var{c})
Returns the coefficients of the integral the polynomial whose coefficients
are represented by the vector @var{c}.

The constant of integration is set to zero.

@item polyreduce (@var{c})
Reduces a polynomial coefficient vector to a minimum number of terms by
stripping off any leading zeros.

@item polyval (@var{c}, @var{x})
Evaluate a polynomial.

@code{polyval (@var{c}, @var{x})} will evaluate the polynomial at the
specified value of @var{x}.

If @var{x} is a vector or matrix, the polynomial is evaluated at each of
the elements of @var{x}.

@item polyvalm (@var{c}, @var{x})
Evaluate a polynomial in the matrix sense.

@code{polyvalm (@var{c}, @var{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 @var{x} must be a square matrix.

@item residue (@var{b}, @var{a}, @var{tol})
If @var{b} and @var{a} are vectors of polynomial coefficients, then
residue calculates the partial fraction expansion corresponding to the
ratio of the two polynomials.

The function @code{residue} returns @var{r}, @var{p}, @var{k}, and
@var{e}, where the vector @var{r} contains the residue terms, @var{p}
contains the pole values, @var{k} contains the coefficients of a direct
polynomial term (if it exists) and @var{e} is a vector containing the
powers of the denominators in the partial fraction terms.

Assuming @var{b} and @var{a} represent polynomials
@iftex
@tex
$P(s)$ and $Q(s)$
@end tex
@end iftex
@ifinfo
 P (s) and Q(s)
@end ifinfo
 we have:
@iftex
@tex
$$
{P(s)\over Q(s)} = \sum_{m=1}^M {r_m\over (s-p_m)^e_m}
  + \sum_{n=1}^N k_n s^{N-n}.
$$
@end tex
@end iftex
@ifinfo

@example
 P(s)    M       r(m)         N
 ---- = SUM -------------  + SUM k(n)*s^(N-n)
 Q(s)   m=1 (s-p(m))^e(m)    n=1
@end example
@end ifinfo

@noindent
where @var{M} is the number of poles (the length of the @var{r},
@var{p}, and @var{e} vectors) and @var{N} is the length of the @var{k}
vector.

The argument @var{tol} is 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 than @var{tol}, the
imaginary part is discarded.  If two poles are farther apart than
@var{tol} they are distinct.  For example,

Example:

@example
 b = [1, 1, 1];
 a = [1, -5, 8, -4];

 [r, p, k, e] = residue (b, a)
@end example

@noindent
returns

@example
r = [-2, 7, 3]

p = [2, 2, 1]

k = [](0x0)

e = [1, 2, 1]
@end example

@noindent
which implies the following partial fraction expansion
@iftex
@tex
$$
{s^2+s+1\over s^3-5s^2+8s-4} = {-2\over s-2} + {7\over (s-2)^2} + {3\over s-1}
$$
@end tex
@end iftex
@ifinfo

@example
        s^2 + s + 1       -2        7        3
   ------------------- = ----- + ------- + -----
   s^3 - 5s^2 + 8s - 4   (s-2)   (s-2)^2   (s-1)
@end example
@end ifinfo

@item roots (@var{v})

For a vector @var{v} with @var{n} components, return
the roots of the polynomial
@iftex
@tex
$$
v_1 z^{n-1} + \cdots + v_{n-1} z + v_n.
$$
@end tex
@end iftex
@ifinfo

@example
v(1) * z^(n-1) + ... + v(n-1) * z + v(n).
@end example
@end ifinfo
@end ftable