2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
904
|
19 |
3368
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} polyderiv (@var{c}) |
5216
|
22 ## @deftypefnx {Function File} {[@var{q}] =} polyder (@var{b}, @var{a}) |
|
23 ## @deftypefnx {Function File} {[@var{q}, @var{r}] =} polyder (@var{b}, @var{a}) |
3368
|
24 ## Return the coefficients of the derivative of the polynomial whose |
5216
|
25 ## coefficients are given by vector @var{c}. If a pair of polynomials |
|
26 ## is given @var{b} and @var{a}, the derivative of the product is |
|
27 ## returned in @var{q}, or the quotient numerator in @var{q} and the |
|
28 ## quotient denominator in @var{r}. |
3368
|
29 ## @end deftypefn |
3457
|
30 ## @seealso{poly, polyinteg, polyreduce, roots, conv, deconv, residue, |
5216
|
31 ## filter, polygcd, polyval, and polyvalm} |
1025
|
32 |
3202
|
33 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
34 ## Created: June 1994 |
|
35 ## Adapted-By: jwe |
561
|
36 |
5216
|
37 function [q, r] = polyderiv (p, a) |
|
38 |
5217
|
39 if (nargin == 1 || nargin == 2) |
|
40 if (! isvector (p)) |
5216
|
41 error ("polyderiv: argument must be a vector"); |
|
42 endif |
5217
|
43 if (nargin == 2) |
|
44 if (! isvector (a)) |
|
45 error ("polyderiv: argument must be a vector"); |
|
46 endif |
|
47 if (nargout == 1) |
|
48 ## derivative of p*a returns a single polynomial |
|
49 q = polyderiv (conv (p, a)); |
|
50 else |
|
51 ## derivative of p/a returns numerator and denominator |
|
52 r = conv (a, a); |
|
53 if (numel (p) == 1) |
|
54 q = -p * polyderiv (a); |
|
55 elseif (numel (a) == 1) |
|
56 q = a * polyderiv (p); |
|
57 else |
|
58 q = conv (polyderiv (p), a) - conv (p, polyderiv (a)); |
|
59 q = polyreduce (q); |
|
60 endif |
|
61 |
|
62 ## remove common factors from numerator and denominator |
|
63 x = polygcd (q, r); |
|
64 if (length(x) != 1) |
|
65 q = deconv (q, x); |
|
66 r = deconv (r, x); |
|
67 endif |
|
68 |
|
69 ## move all the gain into the numerator |
|
70 q = q/r(1); |
|
71 r = r/r(1); |
|
72 endif |
5216
|
73 else |
5217
|
74 lp = numel (p); |
|
75 if (lp == 1) |
|
76 q = 0; |
|
77 return; |
|
78 elseif (lp == 0) |
|
79 q = []; |
|
80 return; |
5216
|
81 endif |
561
|
82 |
5217
|
83 ## Force P to be a row vector. |
|
84 p = p(:).'; |
5135
|
85 |
5217
|
86 q = p(1:(lp-1)) .* [(lp-1):-1:1]; |
5216
|
87 endif |
|
88 else |
5217
|
89 usage ("q = polyderiv (p) or q = polyderiv (b, a) or [q, r] = polyderiv (b, a)"); |
5216
|
90 endif |
561
|
91 |
5217
|
92 |
561
|
93 endfunction |