3294
|
1 @c Copyright (C) 1996, 1997 John W. Eaton |
|
2 @c This is part of the Octave manual. |
|
3 @c For copying conditions, see the file gpl.texi. |
|
4 |
|
5 @node Polynomial Manipulations, Control Theory, Sets, Top |
|
6 @chapter Polynomial Manipulations |
|
7 |
|
8 In Octave, a polynomial is represented by its coefficients (arranged |
|
9 in descending order). For example, a vector |
|
10 @iftex |
|
11 @end iftex |
|
12 @ifinfo |
|
13 $c$ |
|
14 @end ifinfo |
|
15 of length |
|
16 @iftex |
|
17 @tex |
|
18 $N+1$ |
|
19 @end tex |
|
20 @ifinfo |
|
21 @var{N+1} |
|
22 @end ifinfo |
|
23 corresponds to the following polynomial of order |
|
24 @iftex |
|
25 @tex |
|
26 $N$ |
|
27 $$ |
|
28 p (x) = c_1 x^N + ... + c_N x + c_{N+1}. |
|
29 $$ |
|
30 @end tex |
|
31 @end iftex |
|
32 @ifinfo |
|
33 @var{N} |
|
34 |
|
35 @example |
|
36 p(x) = @var{c}(1) x^@var{N} + ... + @var{c}(@var{N}) x + @var{c}(@var{N}+1). |
|
37 @end example |
|
38 @end ifinfo |
|
39 |
|
40 @deftypefn {Function File} {} compan (@var{c}) |
|
41 Compute the companion matrix corresponding to polynomial coefficient |
|
42 vector @var{c}. |
|
43 |
|
44 The companion matrix is |
|
45 @iftex |
|
46 @tex |
|
47 $$ |
|
48 A = \left[\matrix{ |
|
49 -c_2/c_1 & -c_3/c_1 & \cdots & -c_N/c_1 & -c_{N+1}/c_1\cr |
|
50 1 & 0 & \cdots & 0 & 0 \cr |
|
51 0 & 1 & \cdots & 0 & 0 \cr |
|
52 \vdots & \vdots & \ddots & \vdots & \vdots \cr |
|
53 0 & 0 & \cdots & 1 & 0}\right]. |
|
54 $$ |
|
55 @end tex |
|
56 @end iftex |
|
57 @ifinfo |
|
58 |
|
59 @smallexample |
|
60 _ _ |
|
61 | -c(2)/c(1) -c(3)/c(1) ... -c(N)/c(1) -c(N+1)/c(1) | |
|
62 | 1 0 ... 0 0 | |
|
63 | 0 1 ... 0 0 | |
|
64 A = | . . . . . | |
|
65 | . . . . . | |
|
66 | . . . . . | |
|
67 |_ 0 0 ... 1 0 _| |
|
68 @end smallexample |
|
69 @end ifinfo |
|
70 |
|
71 The eigenvalues of the companion matrix are equal to the roots of the |
|
72 polynomial. |
|
73 @end deftypefn |
|
74 |
|
75 @deftypefn {Function File} {} conv (@var{a}, @var{b}) |
|
76 Convolve two vectors. |
|
77 |
|
78 @code{y = conv (a, b)} returns a vector of length equal to |
|
79 @code{length (a) + length (b) - 1}. |
|
80 If @var{a} and @var{b} are polynomial coefficient vectors, @code{conv} |
|
81 returns the coefficients of the product polynomial. |
|
82 @end deftypefn |
|
83 |
|
84 @deftypefn {Function File} {} deconv (@var{y}, @var{a}) |
|
85 Deconvolve two vectors. |
|
86 |
|
87 @code{[b, r] = deconv (y, a)} solves for @var{b} and @var{r} such that |
|
88 @code{y = conv (a, b) + r}. |
|
89 |
|
90 If @var{y} and @var{a} are polynomial coefficient vectors, @var{b} will |
|
91 contain the coefficients of the polynomial quotient and @var{r} will be |
|
92 a remander polynomial of lowest order. |
|
93 @end deftypefn |
|
94 |
|
95 @deftypefn {Function File} {} poly (@var{a}) |
|
96 If @var{a} is a square @var{N}-by-@var{N} matrix, @code{poly (@var{a})} |
|
97 is the row vector of the coefficients of @code{det (z * eye (N) - a)}, |
|
98 the characteristic polynomial of @var{a}. If @var{x} is a vector, |
|
99 @code{poly (@var{x})} is a vector of coefficients of the polynomial |
|
100 whose roots are the elements of @var{x}. |
|
101 @end deftypefn |
|
102 |
|
103 @deftypefn {Function File} {} polyderiv (@var{c}) |
|
104 Return the coefficients of the derivative of the polynomial whose |
|
105 coefficients are given by vector @var{c}. |
|
106 @end deftypefn |
|
107 |
|
108 @deftypefn {Function File} {[@var{p}, @var{yf}] =} polyfit (@var{x}, @var{y}, @var{n}) |
|
109 Return the coefficients of a polynomial @var{p}(@var{x}) of degree |
|
110 @var{n} that minimizes |
|
111 @iftex |
|
112 @tex |
|
113 $$ |
|
114 \sum_{i=1}^N (p(x_i) - y_i)^2 |
|
115 $$ |
|
116 @end tex |
|
117 @end iftex |
|
118 @ifinfo |
|
119 @code{sumsq (p(x(i)) - y(i))}, |
|
120 @end ifinfo |
|
121 to best fit the data in the least squares sense. |
|
122 @end deftypefn |
|
123 |
|
124 If two output arguments are requested, the second contains the values of |
|
125 the polynomial for each value of @var{x}. |
|
126 |
|
127 @deftypefn {Function File} {} polyinteg (@var{c}) |
|
128 Return the coefficients of the integral of the polynomial whose |
|
129 coefficients are represented by the vector @var{c}. |
|
130 |
|
131 The constant of integration is set to zero. |
|
132 @end deftypefn |
|
133 |
|
134 @deftypefn {Function File} {} polyreduce (@var{c}) |
|
135 Reduces a polynomial coefficient vector to a minimum number of terms by |
|
136 stripping off any leading zeros. |
|
137 @end deftypefn |
|
138 |
|
139 @deftypefn {Function File} {} polyval (@var{c}, @var{x}) |
|
140 Evaluate a polynomial. |
|
141 |
|
142 @code{polyval (@var{c}, @var{x})} will evaluate the polynomial at the |
|
143 specified value of @var{x}. |
|
144 |
|
145 If @var{x} is a vector or matrix, the polynomial is evaluated at each of |
|
146 the elements of @var{x}. |
|
147 @end deftypefn |
|
148 |
|
149 @deftypefn {Function File} {} polyvalm (@var{c}, @var{x}) |
|
150 Evaluate a polynomial in the matrix sense. |
|
151 |
|
152 @code{polyvalm (@var{c}, @var{x})} will evaluate the polynomial in the |
|
153 matrix sense, i.e. matrix multiplication is used instead of element by |
|
154 element multiplication as is used in polyval. |
|
155 |
|
156 The argument @var{x} must be a square matrix. |
|
157 @end deftypefn |
|
158 |
|
159 @deftypefn {Function File} {} residue (@var{b}, @var{a}, @var{tol}) |
|
160 If @var{b} and @var{a} are vectors of polynomial coefficients, then |
|
161 residue calculates the partial fraction expansion corresponding to the |
|
162 ratio of the two polynomials. |
|
163 @cindex partial fraction expansion |
|
164 |
|
165 The function @code{residue} returns @var{r}, @var{p}, @var{k}, and |
|
166 @var{e}, where the vector @var{r} contains the residue terms, @var{p} |
|
167 contains the pole values, @var{k} contains the coefficients of a direct |
|
168 polynomial term (if it exists) and @var{e} is a vector containing the |
|
169 powers of the denominators in the partial fraction terms. |
|
170 |
|
171 Assuming @var{b} and @var{a} represent polynomials |
|
172 @iftex |
|
173 @tex |
|
174 $P(s)$ and $Q(s)$ |
|
175 @end tex |
|
176 @end iftex |
|
177 @ifinfo |
|
178 P (s) and Q(s) |
|
179 @end ifinfo |
|
180 we have: |
|
181 @iftex |
|
182 @tex |
|
183 $$ |
|
184 {P(s)\over Q(s)} = \sum_{m=1}^M {r_m\over (s-p_m)^e_m} |
|
185 + \sum_{i=1}^N k_i s^{N-i}. |
|
186 $$ |
|
187 @end tex |
|
188 @end iftex |
|
189 @ifinfo |
|
190 |
|
191 @example |
|
192 P(s) M r(m) N |
|
193 ---- = SUM ------------- + SUM k(i)*s^(N-i) |
|
194 Q(s) m=1 (s-p(m))^e(m) i=1 |
|
195 @end example |
|
196 @end ifinfo |
|
197 |
|
198 @noindent |
|
199 where @var{M} is the number of poles (the length of the @var{r}, |
|
200 @var{p}, and @var{e} vectors) and @var{N} is the length of the @var{k} |
|
201 vector. |
|
202 |
|
203 The argument @var{tol} is optional, and if not specified, a default |
|
204 value of 0.001 is assumed. The tolerance value is used to determine |
|
205 whether poles with small imaginary components are declared real. It is |
|
206 also used to determine if two poles are distinct. If the ratio of the |
|
207 imaginary part of a pole to the real part is less than @var{tol}, the |
|
208 imaginary part is discarded. If two poles are farther apart than |
|
209 @var{tol} they are distinct. For example, |
|
210 |
|
211 @example |
|
212 @group |
|
213 b = [1, 1, 1]; |
|
214 a = [1, -5, 8, -4]; |
|
215 [r, p, k, e] = residue (b, a); |
|
216 @result{} r = [-2, 7, 3] |
|
217 @result{} p = [2, 2, 1] |
|
218 @result{} k = [](0x0) |
|
219 @result{} e = [1, 2, 1] |
|
220 @end group |
|
221 @end example |
|
222 |
|
223 @noindent |
|
224 which implies the following partial fraction expansion |
|
225 @iftex |
|
226 @tex |
|
227 $$ |
|
228 {s^2+s+1\over s^3-5s^2+8s-4} = {-2\over s-2} + {7\over (s-2)^2} + {3\over s-1} |
|
229 $$ |
|
230 @end tex |
|
231 @end iftex |
|
232 @ifinfo |
|
233 |
|
234 @example |
|
235 s^2 + s + 1 -2 7 3 |
|
236 ------------------- = ----- + ------- + ----- |
|
237 s^3 - 5s^2 + 8s - 4 (s-2) (s-2)^2 (s-1) |
|
238 @end example |
|
239 @end ifinfo |
|
240 @end deftypefn |
|
241 |
|
242 @deftypefn {Function File} {} roots (@var{v}) |
|
243 |
|
244 For a vector @var{v} with @var{N} components, return |
|
245 the roots of the polynomial |
|
246 @iftex |
|
247 @tex |
|
248 $$ |
|
249 v_1 z^{N-1} + \cdots + v_{N-1} z + v_N. |
|
250 $$ |
|
251 @end tex |
|
252 @end iftex |
|
253 @ifinfo |
|
254 |
|
255 @example |
|
256 v(1) * z^(N-1) + ... + v(N-1) * z + v(N). |
|
257 @end example |
|
258 @end ifinfo |
|
259 @end deftypefn |