Symbolic Math Toolbox    

Simple Example

Suppose we want to write an M-file that takes two polynomials or two integers and returns their greatest common divisor. For example, the greatest common divisor of 14 and 21 is 7. The greatest common divisor of x^2-y^2 and x^3-y^3 is x - y.

The first thing we need to know is how to call the greatest common divisor function in Maple. We use the mhelp function to bring up the Maple online help for the greatest common divisor (gcd).

Let's try the gcd function

which returns

Since we now know the Maple calling syntax for gcd, we can write a simple M-file to calculate the greatest common divisor. First, create the M-file gcd in the @sym directory and include the commands below.

If we run this file

we get

Now let's extend our function so that we can take the gcd of two matrices in a pointwise fashion:

Running this on some test data

we get the result


  Using Maple Functions Vectorized Example