Mercurial > octave-nkf
changeset 12803:b7a6a3644f3b
codesprint: Deprecate polyderiv.m
* deprecate/module.mk, polynomial/module.mk, polyder.m, polyderiv.m: Deprecate
polyderiv.m
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 16 Jul 2011 10:56:19 -0700 |
parents | 412882f498b4 |
children | a44ec6d33cc9 |
files | NEWS scripts/deprecated/module.mk scripts/deprecated/polyderiv.m scripts/polynomial/module.mk scripts/polynomial/polyder.m scripts/polynomial/polyderiv.m |
diffstat | 6 files changed, 180 insertions(+), 115 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Sat Jul 16 12:52:47 2011 -0500 +++ b/NEWS Sat Jul 16 10:56:19 2011 -0700 @@ -34,6 +34,7 @@ __error_text__ error_text is_duplicate_entry + polyderiv studentize sylvester_matrix
--- a/scripts/deprecated/module.mk Sat Jul 16 12:52:47 2011 -0500 +++ b/scripts/deprecated/module.mk Sat Jul 16 10:56:19 2011 -0700 @@ -18,6 +18,7 @@ deprecated/isstr.m \ deprecated/krylovb.m \ deprecated/perror.m \ + deprecated/polyderiv.m \ deprecated/replot.m \ deprecated/saveimage.m \ deprecated/setstr.m \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/deprecated/polyderiv.m Sat Jul 16 10:56:19 2011 -0700 @@ -0,0 +1,108 @@ +## Copyright (C) 1994-2011 John W. Eaton +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} polyderiv (@var{p}) +## @deftypefnx {Function File} {[@var{k}] =} polyderiv (@var{a}, @var{b}) +## @deftypefnx {Function File} {[@var{q}, @var{d}] =} polyderiv (@var{b}, @var{a}) +## Return the coefficients of the derivative of the polynomial whose +## coefficients are given by the vector @var{p}. If a pair of polynomials +## is given, return the derivative of the product @math{@var{a}*@var{b}}. +## If two inputs and two outputs are given, return the derivative of the +## polynomial quotient @math{@var{b}/@var{a}}. The quotient numerator is +## in @var{q} and the denominator in @var{d}. +## @seealso{poly, polyint, polyreduce, roots, conv, deconv, residue, +## filter, polygcd, polyval, polyvalm} +## @end deftypefn + +## Author: Tony Richardson <arichard@stark.cc.oh.us> +## Created: June 1994 +## Adapted-By: jwe + +function [q, d] = polyderiv (p, a) + + persistent warned = false; + if (! warned) + warned = true; + warning ("Octave:deprecated-function", + "polyderiv is obsolete and will be removed from a future version of Octave; please use polyder instead"); + endif + + if (nargin == 1 || nargin == 2) + if (! isvector (p)) + error ("polyderiv: argument must be a vector"); + endif + if (nargin == 2) + if (! isvector (a)) + error ("polyderiv: argument must be a vector"); + endif + if (nargout == 1) + ## derivative of p*a returns a single polynomial + q = polyderiv (conv (p, a)); + else + ## derivative of p/a returns numerator and denominator + d = conv (a, a); + if (numel (p) == 1) + q = -p * polyderiv (a); + elseif (numel (a) == 1) + q = a * polyderiv (p); + else + q = conv (polyderiv (p), a) - conv (p, polyderiv (a)); + q = polyreduce (q); + endif + + ## remove common factors from numerator and denominator + x = polygcd (q, d); + if (length(x) != 1) + q = deconv (q, x); + d = deconv (d, x); + endif + + ## move all the gain into the numerator + q = q/d(1); + d = d/d(1); + endif + else + lp = numel (p); + if (lp == 1) + q = 0; + return; + elseif (lp == 0) + q = []; + return; + endif + + ## Force P to be a row vector. + p = p(:).'; + + q = p(1:(lp-1)) .* [(lp-1):-1:1]; + endif + else + print_usage (); + endif + +endfunction + +%!assert(all (all (polyderiv ([1, 2, 3]) == [2, 2]))); + +%!assert(polyderiv (13) == 0); + +%!error polyderiv ([]); + +%!error polyderiv ([1, 2; 3, 4]); +
--- a/scripts/polynomial/module.mk Sat Jul 16 12:52:47 2011 -0500 +++ b/scripts/polynomial/module.mk Sat Jul 16 10:56:19 2011 -0700 @@ -10,7 +10,6 @@ polynomial/poly.m \ polynomial/polyaffine.m \ polynomial/polyder.m \ - polynomial/polyderiv.m \ polynomial/polyfit.m \ polynomial/polygcd.m \ polynomial/polyint.m \
--- a/scripts/polynomial/polyder.m Sat Jul 16 12:52:47 2011 -0500 +++ b/scripts/polynomial/polyder.m Sat Jul 16 10:56:19 2011 -0700 @@ -1,4 +1,4 @@ -## Copyright (C) 1995-2011 John W. Eaton +## Copyright (C) 1994-2011 John W. Eaton ## ## This file is part of Octave. ## @@ -17,27 +17,84 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {} polyderiv (@var{p}) -## @deftypefnx {Function File} {[@var{k}] =} polyderiv (@var{a}, @var{b}) -## @deftypefnx {Function File} {[@var{q}, @var{d}] =} polyderiv (@var{b}, @var{a}) -## An alias for @code{polyderiv}. -## @seealso{polyderiv} +## @deftypefn {Function File} {} polyder (@var{p}) +## @deftypefnx {Function File} {[@var{k}] =} polyder (@var{a}, @var{b}) +## @deftypefnx {Function File} {[@var{q}, @var{d}] =} polyder (@var{b}, @var{a}) +## Return the coefficients of the derivative of the polynomial whose +## coefficients are given by the vector @var{p}. If a pair of polynomials +## is given, return the derivative of the product @math{@var{a}*@var{b}}. +## If two inputs and two outputs are given, return the derivative of the +## polynomial quotient @math{@var{b}/@var{a}}. The quotient numerator is +## in @var{q} and the denominator in @var{d}. +## @seealso{poly, polyint, polyreduce, roots, conv, deconv, residue, +## filter, polygcd, polyval, polyvalm} ## @end deftypefn -## Author: John W. Eaton +## Author: Tony Richardson <arichard@stark.cc.oh.us> +## Created: June 1994 +## Adapted-By: jwe function [q, d] = polyder (p, a) - if (nargin == 1) - q = polyderiv (p); - elseif (nargin == 2) - if (nargout == 2) - [q, d] = polyderiv (p, a); + if (nargin == 1 || nargin == 2) + if (! isvector (p)) + error ("polyder: argument must be a vector"); + endif + if (nargin == 2) + if (! isvector (a)) + error ("polyder: argument must be a vector"); + endif + if (nargout == 1) + ## derivative of p*a returns a single polynomial + q = polyder (conv (p, a)); + else + ## derivative of p/a returns numerator and denominator + d = conv (a, a); + if (numel (p) == 1) + q = -p * polyder (a); + elseif (numel (a) == 1) + q = a * polyder (p); + else + q = conv (polyder (p), a) - conv (p, polyder (a)); + q = polyreduce (q); + endif + + ## remove common factors from numerator and denominator + x = polygcd (q, d); + if (length(x) != 1) + q = deconv (q, x); + d = deconv (d, x); + endif + + ## move all the gain into the numerator + q = q/d(1); + d = d/d(1); + endif else - q = polyderiv (p, a); + lp = numel (p); + if (lp == 1) + q = 0; + return; + elseif (lp == 0) + q = []; + return; + endif + + ## Force P to be a row vector. + p = p(:).'; + + q = p(1:(lp-1)) .* [(lp-1):-1:1]; endif else print_usage (); endif endfunction + + +%!assert(all (all (polyder ([1, 2, 3]) == [2, 2]))); +%!assert(polyder (13) == 0); + +%!error polyder ([]); +%!error polyder ([1, 2; 3, 4]); +
--- a/scripts/polynomial/polyderiv.m Sat Jul 16 12:52:47 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -## Copyright (C) 1994-2011 John W. Eaton -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} polyderiv (@var{p}) -## @deftypefnx {Function File} {[@var{k}] =} polyderiv (@var{a}, @var{b}) -## @deftypefnx {Function File} {[@var{q}, @var{d}] =} polyderiv (@var{b}, @var{a}) -## Return the coefficients of the derivative of the polynomial whose -## coefficients are given by the vector @var{p}. If a pair of polynomials -## is given, return the derivative of the product @math{@var{a}*@var{b}}. -## If two inputs and two outputs are given, return the derivative of the -## polynomial quotient @math{@var{b}/@var{a}}. The quotient numerator is -## in @var{q} and the denominator in @var{d}. -## @seealso{poly, polyint, polyreduce, roots, conv, deconv, residue, -## filter, polygcd, polyval, polyvalm} -## @end deftypefn - -## Author: Tony Richardson <arichard@stark.cc.oh.us> -## Created: June 1994 -## Adapted-By: jwe - -function [q, d] = polyderiv (p, a) - - if (nargin == 1 || nargin == 2) - if (! isvector (p)) - error ("polyderiv: argument must be a vector"); - endif - if (nargin == 2) - if (! isvector (a)) - error ("polyderiv: argument must be a vector"); - endif - if (nargout == 1) - ## derivative of p*a returns a single polynomial - q = polyderiv (conv (p, a)); - else - ## derivative of p/a returns numerator and denominator - d = conv (a, a); - if (numel (p) == 1) - q = -p * polyderiv (a); - elseif (numel (a) == 1) - q = a * polyderiv (p); - else - q = conv (polyderiv (p), a) - conv (p, polyderiv (a)); - q = polyreduce (q); - endif - - ## remove common factors from numerator and denominator - x = polygcd (q, d); - if (length(x) != 1) - q = deconv (q, x); - d = deconv (d, x); - endif - - ## move all the gain into the numerator - q = q/d(1); - d = d/d(1); - endif - else - lp = numel (p); - if (lp == 1) - q = 0; - return; - elseif (lp == 0) - q = []; - return; - endif - - ## Force P to be a row vector. - p = p(:).'; - - q = p(1:(lp-1)) .* [(lp-1):-1:1]; - endif - else - print_usage (); - endif - -endfunction - -%!assert(all (all (polyderiv ([1, 2, 3]) == [2, 2]))); - -%!assert(polyderiv (13) == 0); - -%!error polyderiv ([]); - -%!error polyderiv ([1, 2; 3, 4]); -