1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.51
from ./octave.texi on 18 June 1999 -->
<TITLE>GNU Octave - Polynomial Manipulations</TITLE>
</HEAD>
<BODY>
Go to the <A HREF="octave_1.html">first</A>, <A HREF="octave_24.html">previous</A>, <A HREF="octave_26.html">next</A>, <A HREF="octave_40.html">last</A> section, <A HREF="octave_toc.html">table of contents</A>.
<P><HR><P>
<H1><A NAME="SEC160" HREF="octave_toc.html#TOC160">Polynomial Manipulations</A></H1>
<P>
In Octave, a polynomial is represented by its coefficients (arranged
in descending order). For example, a vector
$c$
of length
<VAR>N</VAR>
</P>
<PRE>
p(x) = <VAR>c</VAR>(1) x^<VAR>N</VAR> + ... + <VAR>c</VAR>(<VAR>N</VAR>) x + <VAR>c</VAR>(<VAR>N</VAR>+1).
</PRE>
<P>
<DL>
<DT><U>Function File:</U> <B>compan</B> <I>(<VAR>c</VAR>)</I>
<DD><A NAME="IDX776"></A>
Compute the companion matrix corresponding to polynomial coefficient
vector <VAR>c</VAR>.
</P>
<P>
The companion matrix is
</P>
<PRE>
_ _
| -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 _|
</PRE>
<P>
The eigenvalues of the companion matrix are equal to the roots of the
polynomial.
</DL>
</P>
<P>
<DL>
<DT><U>Function File:</U> <B>conv</B> <I>(<VAR>a</VAR>, <VAR>b</VAR>)</I>
<DD><A NAME="IDX777"></A>
Convolve two vectors.
</P>
<P>
<CODE>y = conv (a, b)</CODE> returns a vector of length equal to
<CODE>length (a) + length (b) - 1</CODE>.
If <VAR>a</VAR> and <VAR>b</VAR> are polynomial coefficient vectors, <CODE>conv</CODE>
returns the coefficients of the product polynomial.
</DL>
</P>
<P>
<DL>
<DT><U>Function File:</U> <B>deconv</B> <I>(<VAR>y</VAR>, <VAR>a</VAR>)</I>
<DD><A NAME="IDX778"></A>
Deconvolve two vectors.
</P>
<P>
<CODE>[b, r] = deconv (y, a)</CODE> solves for <VAR>b</VAR> and <VAR>r</VAR> such that
<CODE>y = conv (a, b) + r</CODE>.
</P>
<P>
If <VAR>y</VAR> and <VAR>a</VAR> are polynomial coefficient vectors, <VAR>b</VAR> will
contain the coefficients of the polynomial quotient and <VAR>r</VAR> will be
a remander polynomial of lowest order.
</DL>
</P>
<P>
<DL>
<DT><U>Function File:</U> <B>poly</B> <I>(<VAR>a</VAR>)</I>
<DD><A NAME="IDX779"></A>
If <VAR>a</VAR> is a square <VAR>N</VAR>-by-<VAR>N</VAR> matrix, <CODE>poly (<VAR>a</VAR>)</CODE>
is the row vector of the coefficients of <CODE>det (z * eye (N) - a)</CODE>,
the characteristic polynomial of <VAR>a</VAR>. If <VAR>x</VAR> is a vector,
<CODE>poly (<VAR>x</VAR>)</CODE> is a vector of coefficients of the polynomial
whose roots are the elements of <VAR>x</VAR>.
</DL>
</P>
<P>
<DL>
<DT><U>Function File:</U> <B>polyderiv</B> <I>(<VAR>c</VAR>)</I>
<DD><A NAME="IDX780"></A>
Return the coefficients of the derivative of the polynomial whose
coefficients are given by vector <VAR>c</VAR>.
</DL>
</P>
<P>
<DL>
<DT><U>Function File:</U> [<VAR>p</VAR>, <VAR>yf</VAR>] = <B>polyfit</B> <I>(<VAR>x</VAR>, <VAR>y</VAR>, <VAR>n</VAR>)</I>
<DD><A NAME="IDX781"></A>
Return the coefficients of a polynomial <VAR>p</VAR>(<VAR>x</VAR>) of degree
<VAR>n</VAR> that minimizes
<CODE>sumsq (p(x(i)) - y(i))</CODE>,
to best fit the data in the least squares sense.
</DL>
</P>
<P>
If two output arguments are requested, the second contains the values of
the polynomial for each value of <VAR>x</VAR>.
</P>
<P>
<DL>
<DT><U>Function File:</U> <B>polyinteg</B> <I>(<VAR>c</VAR>)</I>
<DD><A NAME="IDX782"></A>
Return the coefficients of the integral of the polynomial whose
coefficients are represented by the vector <VAR>c</VAR>.
</P>
<P>
The constant of integration is set to zero.
</DL>
</P>
<P>
<DL>
<DT><U>Function File:</U> <B>polyreduce</B> <I>(<VAR>c</VAR>)</I>
<DD><A NAME="IDX783"></A>
Reduces a polynomial coefficient vector to a minimum number of terms by
stripping off any leading zeros.
</DL>
</P>
<P>
<DL>
<DT><U>Function File:</U> <B>polyval</B> <I>(<VAR>c</VAR>, <VAR>x</VAR>)</I>
<DD><A NAME="IDX784"></A>
Evaluate a polynomial.
</P>
<P>
<CODE>polyval (<VAR>c</VAR>, <VAR>x</VAR>)</CODE> will evaluate the polynomial at the
specified value of <VAR>x</VAR>.
</P>
<P>
If <VAR>x</VAR> is a vector or matrix, the polynomial is evaluated at each of
the elements of <VAR>x</VAR>.
</DL>
</P>
<P>
<DL>
<DT><U>Function File:</U> <B>polyvalm</B> <I>(<VAR>c</VAR>, <VAR>x</VAR>)</I>
<DD><A NAME="IDX785"></A>
Evaluate a polynomial in the matrix sense.
</P>
<P>
<CODE>polyvalm (<VAR>c</VAR>, <VAR>x</VAR>)</CODE> 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.
</P>
<P>
The argument <VAR>x</VAR> must be a square matrix.
</DL>
</P>
<P>
<DL>
<DT><U>Function File:</U> <B>residue</B> <I>(<VAR>b</VAR>, <VAR>a</VAR>, <VAR>tol</VAR>)</I>
<DD><A NAME="IDX786"></A>
If <VAR>b</VAR> and <VAR>a</VAR> are vectors of polynomial coefficients, then
residue calculates the partial fraction expansion corresponding to the
ratio of the two polynomials.
<A NAME="IDX787"></A>
</P>
<P>
The function <CODE>residue</CODE> returns <VAR>r</VAR>, <VAR>p</VAR>, <VAR>k</VAR>, and
<VAR>e</VAR>, where the vector <VAR>r</VAR> contains the residue terms, <VAR>p</VAR>
contains the pole values, <VAR>k</VAR> contains the coefficients of a direct
polynomial term (if it exists) and <VAR>e</VAR> is a vector containing the
powers of the denominators in the partial fraction terms.
</P>
<P>
Assuming <VAR>b</VAR> and <VAR>a</VAR> represent polynomials
P (s) and Q(s)
we have:
</P>
<PRE>
P(s) M r(m) N
---- = SUM ------------- + SUM k(i)*s^(N-i)
Q(s) m=1 (s-p(m))^e(m) i=1
</PRE>
<P>
where <VAR>M</VAR> is the number of poles (the length of the <VAR>r</VAR>,
<VAR>p</VAR>, and <VAR>e</VAR> vectors) and <VAR>N</VAR> is the length of the <VAR>k</VAR>
vector.
</P>
<P>
The argument <VAR>tol</VAR> 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</VAR>, the
imaginary part is discarded. If two poles are farther apart than
<VAR>tol</VAR> they are distinct. For example,
</P>
<PRE>
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]
</PRE>
<P>
which implies the following partial fraction expansion
</P>
<PRE>
s^2 + s + 1 -2 7 3
------------------- = ----- + ------- + -----
s^3 - 5s^2 + 8s - 4 (s-2) (s-2)^2 (s-1)
</PRE>
</DL>
<P>
<DL>
<DT><U>Function File:</U> <B>roots</B> <I>(<VAR>v</VAR>)</I>
<DD><A NAME="IDX788"></A>
</P>
<P>
For a vector <VAR>v</VAR> with <VAR>N</VAR> components, return
the roots of the polynomial
</P>
<PRE>
v(1) * z^(N-1) + ... + v(N-1) * z + v(N).
</PRE>
</DL>
<P><HR><P>
Go to the <A HREF="octave_1.html">first</A>, <A HREF="octave_24.html">previous</A>, <A HREF="octave_26.html">next</A>, <A HREF="octave_40.html">last</A> section, <A HREF="octave_toc.html">table of contents</A>.
</BODY>
</HTML>
|