1
## Copyright (C) 2000, 2005, 2006, 2007 Paul Kienzle
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} {@var{q} =} polygcd (@var{b}, @var{a}, @var{tol})
22
## Find greatest common divisor of two polynomials. This is equivalent
23
## to the polynomial found by multiplying together all the common roots.
24
## Together with deconv, you can reduce a ratio of two polynomials.
25
## Tolerance defaults to
29
## Note that this is an unstable
30
## algorithm, so don't try it on large polynomials.
34
## polygcd (poly(1:8), poly(3:12)) - poly(3:8)
35
## @result{} [ 0, 0, 0, 0, 0, 0, 0 ]
36
## deconv (poly(1:8), polygcd (poly(1:8), poly(3:12))) ...
38
## @result{} [ 0, 0, 0 ]
40
## @seealso{poly, polyinteg, polyderiv, polyreduce, roots, conv, deconv,
41
## residue, filter, polyval, and polyvalm}
44
function x = polygcd (b, a, tol)
46
if (nargin == 2 || nargin == 3)
50
if (length (a) == 1 || length (b) == 1)
61
[d, r] = deconv (b, a);
62
nz = find (abs (r) > tol);
67
r = r(nz(1):length(r));