]> Creatis software - CreaPhase.git/blob - octave_packages/m/deprecated/polyderiv.m
update packages
[CreaPhase.git] / octave_packages / m / deprecated / polyderiv.m
1 ## Copyright (C) 1994-2012 John W. Eaton
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 3 of the License, or (at
8 ## your option) 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, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn  {Function File} {} polyderiv (@var{p})
21 ## @deftypefnx {Function File} {[@var{k}] =} polyderiv (@var{a}, @var{b})
22 ## @deftypefnx {Function File} {[@var{q}, @var{d}] =} polyderiv (@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{poly, polyint, polyreduce, roots, conv, deconv, residue,
30 ## filter, polygcd, polyval, polyvalm}
31 ## @end deftypefn
32
33 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
34 ## Created: June 1994
35 ## Adapted-By: jwe
36
37 function [q, d] = polyderiv (p, a)
38
39   persistent warned = false;
40   if (! warned)
41     warned = true;
42     warning ("Octave:deprecated-function",
43              "polyderiv is obsolete and will be removed from a future version of Octave; please use polyder instead");
44   endif
45
46   if (nargin == 1 || nargin == 2)
47     if (! isvector (p))
48       error ("polyderiv: argument must be a vector");
49     endif
50     if (nargin == 2)
51       if (! isvector (a))
52         error ("polyderiv: argument must be a vector");
53       endif
54       if (nargout == 1)
55         ## derivative of p*a returns a single polynomial
56         q = polyderiv (conv (p, a));
57       else
58         ## derivative of p/a returns numerator and denominator
59         d = conv (a, a);
60         if (numel (p) == 1)
61           q = -p * polyderiv (a);
62         elseif (numel (a) == 1)
63           q = a * polyderiv (p);
64         else
65           q = conv (polyderiv (p), a) - conv (p, polyderiv (a));
66           q = polyreduce (q);
67         endif
68
69         ## remove common factors from numerator and denominator
70         x = polygcd (q, d);
71         if (length(x) != 1)
72           q = deconv (q, x);
73           d = deconv (d, x);
74         endif
75
76         ## move all the gain into the numerator
77         q = q/d(1);
78         d = d/d(1);
79       endif
80     else
81       lp = numel (p);
82       if (lp == 1)
83         q = 0;
84         return;
85       elseif (lp == 0)
86         q = [];
87         return;
88       endif
89
90       ## Force P to be a row vector.
91       p = p(:).';
92
93       q = p(1:(lp-1)) .* [(lp-1):-1:1];
94     endif
95   else
96     print_usage ();
97   endif
98
99 endfunction
100
101 %!assert(all (all (polyderiv ([1, 2, 3]) == [2, 2])));
102
103 %!assert(polyderiv (13) == 0);
104
105 %!error polyderiv ([]);
106
107 %!error polyderiv ([1, 2; 3, 4]);
108