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 |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, 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 |
5216
|
36 ## Paul Kienzle <pkienzle@kienzle.powernet.co.uk> |
|
37 ## handle b/a and b*a |
561
|
38 |
5216
|
39 function [q, r] = polyderiv (p, a) |
|
40 |
|
41 if (nargin < 1 || nargin > 3) |
|
42 usage ("q=polyderiv(p) or q=polyderiv(b,a) or [q, r]=polyderiv(b,a)"); |
561
|
43 endif |
|
44 |
4030
|
45 if (! isvector (p)) |
3085
|
46 error ("polyderiv: argument must be a vector"); |
561
|
47 endif |
|
48 |
5216
|
49 if (nargin == 2) |
|
50 if (! isvector (a)) |
|
51 error ("polyderiv: argument must be a vector"); |
|
52 endif |
|
53 if (nargout == 1) |
|
54 ## derivative of p*a returns a single polynomial |
|
55 q = polyderiv(conv(p,a)); |
|
56 else |
|
57 ## derivative of p/a returns numerator and denominator |
|
58 r = conv(a, a); |
|
59 if numel(p) == 1 |
|
60 q = -p * polyderiv(a); |
|
61 elseif numel(a) == 1 |
|
62 q = a * polyderiv(p); |
|
63 else |
|
64 q = conv(polyderiv(p),a) - conv(p,polyderiv(a)); |
|
65 q = polyreduce(q); |
|
66 endif |
561
|
67 |
5216
|
68 ## remove common factors from numerator and denominator |
|
69 x = polygcd(q,r); |
|
70 if length(x)!=1 |
|
71 q=deconv(q,x); |
|
72 r=deconv(r,x); |
|
73 endif |
5135
|
74 |
5216
|
75 ## move all the gain into the numerator |
|
76 q=q/r(1); |
|
77 r=r/r(1); |
|
78 endif |
|
79 else |
|
80 lp = numel (p); |
|
81 if (lp == 1) |
|
82 q = 0; |
|
83 return; |
|
84 elseif (lp == 0) |
|
85 q = []; |
|
86 return; |
|
87 end |
|
88 |
|
89 ## Force P to be a row vector. |
|
90 p = p(:).'; |
|
91 |
|
92 q = p (1:(lp-1)) .* [(lp-1):-1:1]; |
|
93 endif |
561
|
94 |
|
95 endfunction |