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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
2313
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
904
|
18 |
3368
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} polyderiv (@var{c}) |
6850
|
21 ## @deftypefnx {Function File} {[@var{q}] =} polyderiv (@var{b}, @var{a}) |
|
22 ## @deftypefnx {Function File} {[@var{q}, @var{r}] =} polyderiv (@var{b}, @var{a}) |
3368
|
23 ## Return the coefficients of the derivative of the polynomial whose |
5216
|
24 ## coefficients are given by vector @var{c}. If a pair of polynomials |
|
25 ## is given @var{b} and @var{a}, the derivative of the product is |
|
26 ## returned in @var{q}, or the quotient numerator in @var{q} and the |
|
27 ## quotient denominator in @var{r}. |
5642
|
28 ## @seealso{poly, polyinteg, polyreduce, roots, conv, deconv, residue, |
|
29 ## filter, polygcd, polyval, polyvalm} |
3368
|
30 ## @end deftypefn |
1025
|
31 |
3202
|
32 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
33 ## Created: June 1994 |
|
34 ## Adapted-By: jwe |
561
|
35 |
5216
|
36 function [q, r] = polyderiv (p, a) |
|
37 |
5217
|
38 if (nargin == 1 || nargin == 2) |
|
39 if (! isvector (p)) |
5216
|
40 error ("polyderiv: argument must be a vector"); |
|
41 endif |
5217
|
42 if (nargin == 2) |
|
43 if (! isvector (a)) |
|
44 error ("polyderiv: argument must be a vector"); |
|
45 endif |
|
46 if (nargout == 1) |
|
47 ## derivative of p*a returns a single polynomial |
|
48 q = polyderiv (conv (p, a)); |
|
49 else |
|
50 ## derivative of p/a returns numerator and denominator |
|
51 r = conv (a, a); |
|
52 if (numel (p) == 1) |
|
53 q = -p * polyderiv (a); |
|
54 elseif (numel (a) == 1) |
|
55 q = a * polyderiv (p); |
|
56 else |
|
57 q = conv (polyderiv (p), a) - conv (p, polyderiv (a)); |
|
58 q = polyreduce (q); |
|
59 endif |
|
60 |
|
61 ## remove common factors from numerator and denominator |
|
62 x = polygcd (q, r); |
|
63 if (length(x) != 1) |
|
64 q = deconv (q, x); |
|
65 r = deconv (r, x); |
|
66 endif |
|
67 |
|
68 ## move all the gain into the numerator |
|
69 q = q/r(1); |
|
70 r = r/r(1); |
|
71 endif |
5216
|
72 else |
5217
|
73 lp = numel (p); |
|
74 if (lp == 1) |
|
75 q = 0; |
|
76 return; |
|
77 elseif (lp == 0) |
|
78 q = []; |
|
79 return; |
5216
|
80 endif |
561
|
81 |
5217
|
82 ## Force P to be a row vector. |
|
83 p = p(:).'; |
5135
|
84 |
5217
|
85 q = p(1:(lp-1)) .* [(lp-1):-1:1]; |
5216
|
86 endif |
|
87 else |
6046
|
88 print_usage (); |
5216
|
89 endif |
561
|
90 |
5217
|
91 |
561
|
92 endfunction |