help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Definition of gcd(A,B)


From: dirk
Subject: Definition of gcd(A,B)
Date: Fri, 18 Jun 1999 13:02:47 +0200 (SAST)

I have a need for a term-by-term GCD, i.e.

gcd([6 10;12 15],[9 12; 16 20]) == [3 2;4 5]

The current Octave gcd.m seems to interpret the notation as

gcd([6 10;12 15],[9 12; 16 20]) == gcd([6 10 12 15 9 12 16 20])

and therefore returns 1.

I find this inconvenient and less general, as in the case of the
term-by-term gcd one could easily get the current behaviour
by the using the colon operator.

The "intuitive" definition should to my mind be:

GCD(X) should be the GCD of the elements in vector X
GCD(A) should be a vector of GCD's of columns of matrix A
GCD(A,B,C,...) should be a matrix of GCD's of corresponding
  elements in matrices A,B,C,... which are all scalar or of the
  same shape

I have written such a GCD, which I give a different name to
avoid confusion.

But is the present behaviour of GCD an intentional one, intended
to preserve compatibility with whatever, or just the result of
not having thought out what GCD should mean for non-scalar
arguments?

Dirk Laurie



---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.  To ensure
that development continues, see www.che.wisc.edu/octave/giftform.html
Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
---------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]