| Symbolic Math Toolbox | ![]() |
Simple Example
As an example, you can use the Maple function gcd to calculate the greatest common divisor of two integers or two polynomials. For example, to calculate the greatest common divisor of 14 and 21, enter
To calculate the greatest common divisor of x^2-y^2 and x^3-y^3 enter
To learn more about the function gcd, you can bring up its reference page by entering
As an alternative to typing the maple command every time you want to access gcd, you can write a simple M-file that does this for you. To do so, first create the M-file gcd in the subdirectory toolbox/symbolic/@sym of the directory where MATLAB is installed, and include the following commands in the M-file:
Now, extend the function so that you can take the gcd of two matrices in a pointwise fashion:
function g = gcd(a,b) if any(size(a) ~= size(b)) error('Inputs must have the same size.') end for k = 1: prod(size(a)) g(k) = maple('gcd',a(k), b(k)); end g = reshape(g,size(a));
Running this on some test data
| Using Maple Functions | Vectorized Example | ![]() |
Learn more about the latest releases of MathWorks products: |
| © 1994-2010 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |