1 ## Copyright (C) 1994-2012 John W. Eaton
3 ## This file is part of Octave.
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 3 of the License, or (at
8 ## your option) any later version.
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.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} polyder (@var{p})
21 ## @deftypefnx {Function File} {[@var{k}] =} polyder (@var{a}, @var{b})
22 ## @deftypefnx {Function File} {[@var{q}, @var{d}] =} polyder (@var{b}, @var{a})
23 ## Return the coefficients of the derivative of the polynomial whose
24 ## coefficients are given by the vector @var{p}. If a pair of polynomials
25 ## is given, return the derivative of the product @math{@var{a}*@var{b}}.
26 ## If two inputs and two outputs are given, return the derivative of the
27 ## polynomial quotient @math{@var{b}/@var{a}}. The quotient numerator is
28 ## in @var{q} and the denominator in @var{d}.
29 ## @seealso{polyint, polyval, polyreduce}
32 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
36 function [q, d] = polyder (p, a)
38 if (nargin == 1 || nargin == 2)
40 error ("polyder: argument must be a vector");
44 error ("polyder: argument must be a vector");
47 ## derivative of p*a returns a single polynomial
48 q = polyder (conv (p, a));
50 ## derivative of p/a returns numerator and denominator
54 elseif (numel (a) == 1)
57 q = conv (polyder (p), a) - conv (p, polyder (a));
61 ## remove common factors from numerator and denominator
68 ## move all the gain into the numerator
82 ## Force P to be a row vector.
85 q = p(1:(lp-1)) .* [(lp-1):-1:1];
94 %!assert(all (all (polyder ([1, 2, 3]) == [2, 2])));
95 %!assert(polyder (13) == 0);
98 %!error polyder ([1, 2; 3, 4]);