M-4: Importer-Exporter

In this lesson we give a brief description of some Maple capabilities that may be useful for you:

  • exporting from Maple into LaTeX typesetting
  • importing Maple modules beyond the basic set of commands
  • a few sentences about linear algebra

MaPe\(\LaTeX\)

It is possible to directly export information from Maple to LaTeX. This also can be done in several ways.

  1. Use the latex command (see ?latex for full information) which converts an expression into LaTeX. Here is an example showing the second derivative of \(\mathrm{e}^{x^x}\) via the diff command:
    When we paste this output into LaTeX, we get the following beautiful result:
  2. Export the entire worksheet to LaTeX (see File > Export As). This tends to give you extra formatting that might not be desired, so use it with caution.

In either case, be careful not to assume that everything will be done perfectly. In particular, Maple will tend not to understand what really looks good on paper and will produce very long lines. Use the LaTeX skills that you learned in the first half of the course to polish the automatically-generated code.

with or Without

Hypothetically, let’s say that I want to display all 2-element subsets of a set. While our crash course in programming over the next two lessons contains enough ideas to do this from scratch, this happens to be a procedure that is already available in Maple. It is the function named choose within the combinat package. (It takes two arguments: a set or list of things, and the size of the subsets/sublists you seek. See ?choose for more details.)

There are two basic ways to use a function from a package.

  1. Use the command with(«packagename»); which imports the entire package into your current namespace. Afterwards, the imported function is available by name. For example,
    with(combinat);          # will display all the functions so imported
    choose({a, b, c, d}, 2); # all 6 possible pairs of a, b, c, d
  2. Directly refer to the packaged version of the name, and don’t use with at all. The packaged version of the name is «packagename»[«functionname»]. For example,
    combinat[choose]({a, b, c, d}, 2); # all 6 possible pairs of a, b, c, d

You can get help with an entire package using the typical syntax, e.g. ?combinat. You can also download new packages from the internet and add them to your existing Maple installation, and then import them in this way; see the convex package for example. Package filenames end with .m and they must be placed in one of the directories that appear when you type libname; — you can edit this global variable by editing the Maple init file. (You can’t just put the .m file in the same directory as your .mw file.)

Linear Algebra

Maple deals with linear algebra quite excellently, and you can quickly get up and running by using the Maple help pages. However, Maple’s linear algebra interface has changed a bit over the years so that we feel compelled to offer some bare pieces of advice since it can be difficult to understand where to start otherwise.

  • Do use shortcuts for Vector and Matrix creation:
    • for example fibonacciMatrix := <<0,1>|<1,1>>;
    • see ?LinearAlgebra/General/MVshortcut for details
  • Do use . to multiply Matrices and Vectors
    • e.g.,  fib2 := fibonacciMatrix . fibonacciMatrix;
    • see ?. for details
  • Do use the data types Matrix, Vector, and the package  LinearAlgebra
    • e.g., use the LinearAlgebra[Determinant] function
    • see ?Matrix, ?Vector, and ?LinearAlgebra
  • Don’t use any of the following deprecated (old unsupported) items: matrix, vector, linalg, evalm, &*, or det
    • you are likely to stumble upon them when searching online
  • Watch out that Maple has a data type called Array, separate from Matrix but related
    • in brief an Array is like a Matrix but its number of dimensions does not have to be 2, rather it can also be 1, 3, 4, etc.
    • we’ll mention them briefly in lesson M-7

Onwards and upwards, to Maple programming!

These are course notes for the University of Waterloo's course Math 600: Mathematical Software.
© 2012—. Written and developed by David Pritchard and Stephen Tosh. Contact (goes to the CEMC)