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.
- 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 thediff
command:
When we paste this output into LaTeX, we get the following beautiful result:
- 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.
- 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
- 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
- for example
- Do use
.
to multiply Matrices and Vectors- e.g.,
fib2 := fibonacciMatrix . fibonacciMatrix;
- see
?.
for details
- e.g.,
- Do use the data types
Matrix
,Vector
, and the packageLinearAlgebra
- e.g., use the
LinearAlgebra[Determinant]
function - see
?Matrix
,?Vector
, and?LinearAlgebra
- e.g., use the
- Don’t use any of the following deprecated (old unsupported) items:
matrix
,vector
,linalg
,evalm
,&*
, ordet
- you are likely to stumble upon them when searching online
- Watch out that Maple has a data type called
Array
, separate fromMatrix
but related- in brief an
Array
is like aMatrix
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
- in brief an
Onwards and upwards, to Maple programming!