comparison scripts/polynomial/polyderiv.m @ 5216:5ed60b8b1ac4

[project @ 2005-03-16 19:51:39 by jwe]
author jwe
date Wed, 16 Mar 2005 19:51:46 +0000
parents 8eaef366ab43
children e88886a6934d
comparison
equal deleted inserted replaced
5215:32c569794216 5216:5ed60b8b1ac4
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA 17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
18 ## 02111-1307, USA. 18 ## 02111-1307, USA.
19 19
20 ## -*- texinfo -*- 20 ## -*- texinfo -*-
21 ## @deftypefn {Function File} {} polyderiv (@var{c}) 21 ## @deftypefn {Function File} {} polyderiv (@var{c})
22 ## @deftypefnx {Function File} {[@var{q}] =} polyder (@var{b}, @var{a})
23 ## @deftypefnx {Function File} {[@var{q}, @var{r}] =} polyder (@var{b}, @var{a})
22 ## Return the coefficients of the derivative of the polynomial whose 24 ## Return the coefficients of the derivative of the polynomial whose
23 ## coefficients are given by vector @var{c}. 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}.
24 ## @end deftypefn 29 ## @end deftypefn
25 ##
26 ## @seealso{poly, polyinteg, polyreduce, roots, conv, deconv, residue, 30 ## @seealso{poly, polyinteg, polyreduce, roots, conv, deconv, residue,
27 ## filter, polyval, and polyvalm} 31 ## filter, polygcd, polyval, and polyvalm}
28 32
29 ## Author: Tony Richardson <arichard@stark.cc.oh.us> 33 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
30 ## Created: June 1994 34 ## Created: June 1994
31 ## Adapted-By: jwe 35 ## Adapted-By: jwe
36 ## Paul Kienzle <pkienzle@kienzle.powernet.co.uk>
37 ## handle b/a and b*a
32 38
33 function q = polyderiv (p) 39 function [q, r] = polyderiv (p, a)
34 40
35 if (nargin != 1) 41 if (nargin < 1 || nargin > 3)
36 usage ("polyderiv (vector)"); 42 usage ("q=polyderiv(p) or q=polyderiv(b,a) or [q, r]=polyderiv(b,a)");
37 endif 43 endif
38 44
39 if (! isvector (p)) 45 if (! isvector (p))
40 error ("polyderiv: argument must be a vector"); 46 error ("polyderiv: argument must be a vector");
41 endif 47 endif
42 48
43 lp = numel (p); 49 if (nargin == 2)
44 if (lp == 1) 50 if (! isvector (a))
45 q = 0; 51 error ("polyderiv: argument must be a vector");
46 return; 52 endif
47 elseif (lp == 0) 53 if (nargout == 1)
48 q = []; 54 ## derivative of p*a returns a single polynomial
49 return; 55 q = polyderiv(conv(p,a));
50 end 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
51 67
52 ## Force P to be a row vector. 68 ## remove common factors from numerator and denominator
53 p = p(:).'; 69 x = polygcd(q,r);
70 if length(x)!=1
71 q=deconv(q,x);
72 r=deconv(r,x);
73 endif
54 74
55 q = p(1:(lp-1)) .* [(lp-1):-1:1]; 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
56 94
57 endfunction 95 endfunction