Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

gcd

Greatest common divisor of polynomials

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Syntax

gcd(p, q, …)
gcd(f, g, …)

Description

gcd(p, q, ...) returns the greatest common divisor of the polynomials p, q, … The coefficient ring of the polynomials may either be the integers or the rational numbers, Expr, a residue class ring IntMod(n) with a prime number n, or a domain.

All polynomials must have the same indeterminates and the same coefficient ring.

Polynomial expressions are converted to polynomials. See poly for details.

The return value is of the same type as the input polynomials, i.e., either a polynomial of type DOM_POLY or a polynomial expression.

gcd returns 0 if all arguments are 0, or if no argument is given. If at least one of the arguments is - 1 or 1, then gcd returns 1.

Use igcd if all arguments are known to be integers, since it is much faster than gcd.

Examples

Example 1

The greatest common divisor of two polynomial expressions can be computed as follows:

gcd(6*x^3 + 9*x^2*y^2, 2*x + 2*x*y + 3*y^2 + 3*y^3)

f := (x - sqrt(2))*(x^2 + sqrt(3)*x-1):
g := (x - sqrt(2))*(x - sqrt(3)):
gcd(f, g)

One may also choose polynomials as arguments:

p := poly(2*x^2 - 4*x*y - 2*x + 4*y, [x, y], IntMod(17)):
q := poly(x^2*y - 2*x*y^2, [x, y], IntMod(17)):
gcd(p, q)

delete f, g, p, q:

Parameters

p, q, …

polynomials of type DOM_POLY

f, g, …

polynomial expressions

Return Values

Polynomial or a polynomial expression.

Overloaded By

f, g, p, q

Algorithms

If the arguments are polynomials with coefficients from a domain, then the domain must have the methods "gcd" and "_divide". The method "gcd" must return the greatest common divisor of any number of domain elements. The method "_divide" must divide two domain elements. If domain elements cannot be divided, this method must return FAIL.

See Also

MuPAD Functions

Was this topic helpful?