Download Maple Introductory Programming Guide

Transcript
128
•
Chapter 4: Basic Data Structures
By changing the braces and brackets, you can create a set of lists, list
of lists, or set of sets.
> {seq( [ seq( i^j, j=1..3) ], i=-2..2 ) };
{[−2, 4, −8], [−1, 1, −1], [0, 0, 0], [1, 1, 1], [2, 4, 8]}
Manipulating a List
There are a variety of commands that perform operations on lists.
Testing List Membership To test whether an element is in a list, use
the member command.
> L := [1,2,3];
L := [1, 2, 3]
> member(2, L);
true
> member(5, L);
false
You can also determine the position of an element in a list. If member
returns true and a third argument, for example ‘p‘, is included in the
calling sequence, the element’s position in the list is assigned to p.
> member(2, L, ‘p‘);
true
> p;
2
Concatenating Lists Use the op command to extract the expression
sequence of elements from the individual lists. Concatenate two lists by
creating a new list from the expression sequences.