Department of Mathematics

Math 300: Mathematical Computing

Maple Arrays

Maple has a larger than average set of array structures. Moreover, each array type has many ways it can be initialized. These facts combine to make Maple arrays one of the most complicated parts of a complicated language. Here we discuss some of the structures briefly.

Lists

The most basic array structure in Maple is the ordered list. This is a simple indexed list of elements. Each element can have any type, and could even be another list. The elements of a list are not even required to be of the same type. One makes a list simply by typing the elements, separated by commas, enclosed in brackets. For example,
mylist := [1, 2, 3];
We can then refer to elements of the list using a different bracket notation: mylist[i] refers to the element with index i in mylist. Thus, in the example above, mylist[2] is 2. It is worth emphasizing the two different uses of brackets here: in one case they signify that we are defining a list, in the other, they enclose the index of elements in that list.

Sets

The set differs from the list in Maple in that it is not ordered, and therefore does not contain repeated elements. Sets are created using braces instead of brackets:
myset:={1, 2, 3}
The following example illustrates several of the differences between lists and sets.

a_set:={[1,2],2,2}; a_set:={2, [1, 2]} a_list:=[[1,2],2,2]; a_list:=[[1, 2], 2, 2]

Note that the repeated 2 in the definition for a_set does not appear in the result, and that the order that Maple echoes after the set is defined differs from the order in which the elements were typed. Thus, while we can refer to elements of the set by index, in this case a_set[2] is the list [1,2], even though that was originally typed in the first position. By contrast, the list remains exactly as it was originally typed.

Arrays

The next array structure is actually called an array. Arrays differ from the earlier structures in that they have specific dimensions which need not start at 1. While you can make a list larger just by defining a new element, you must specify the size of an array at the time of definition, and cannot change that size except by a redefinition. There are many ways to define arrays; perhaps their use is best described using an extended example.

A1:=Array(1..2,[1,2]); A1 := [1 2] A2:=Array(1..2,1..2,[[1,2],[3,4]]); A2 := [1 2] [3 4] v:=Array(1..2,1..1,[[1],[1]]); v := [1] [1] w:=Array(-1..0,1..1,[[1],[1]]); w:=Array(-1..0,1..1,{(-1,1)=1,(0,1)=1},datatype=anything,storage=rectangular,order=Fortran_order) w[-1,1]; 1

Note that when the array is defined using negative indices, then the echo does not show its 2-D form.

The truth is that we do not use the Array form that often. It provides more structure than sets or lists, but not so much that it is used commonly.

Vectors and Matrices

Finally, Maple lets us define vectors and matrices, and to operate on those. There are several ways to define these.
v := <1,2,3>;
v := Vector(1..3,[1,2,3]);
are equivalent ways to make a 3-vector. Likewise
m := <<1,2,3>|<4,5,6>>;
m := Matrix(1..3,1..2,[[1,2,3],[4,5,6]]);
are equivalent ways to make a 3×2 matrix. Matrices and vectors are basically like Arrays, except in that they are always indexed starting at 1. There are no elements with negative indices for vectors or matrices. Moreover, the notions of matrix and vector operations are clearly defined for these structures, so we can add them and multiply them when their dimensions allow. Using the linalg or LinearAlgebra packages, we can do much more sophisticated things with them also.

with(LinearAlgebra): v := <1,2,3>: m := <<1,2,3>|<4,5,6>>: Transpose(m).v; [14] [32] M :=; [1 4 1] [2 5 2] [3 6 3] M[2,3]:=-1: LinearSolve(M,v); [1] [0] [0]

Notice that the matrix multiplication symbol is the period '.'. This is to distinguish the matrix operation from the ordinary scalar multiplication.


The "final exam" for this course will take place at 8:00 AM on Tuesday, 12 December. This will be an ordinary 50 minute test. It will be comprehensive, but weighted toward the latter half of the semester. As always, paper notes will be permitted, but no electronic devices will be allowed. A sample exam is available.




A Solution example is available for the quiz. The solution to Test 1 is still available too.




The ultimate assignment is posted.

Department of Mathematics, PO Box 643113, Neill Hall 103, Washington State University, Pullman WA 99164-3113, 509-335-3926, Contact Us
Copyright © 1996-2015 Kevin Cooper