This preview shows page 1. Sign up to view the full content.
Unformatted text preview: ants := [Kathy, Frank, Rene, Niklaus, Liz]; participants := [Kathy , Frank , Rene , Niklaus , Liz ] Thus, a list is an expression sequence enclosed in square brackets. Order Maple preserves the order and repetition of elements in a list. Thus, [a,b,c], [b,c,a], and [a,a,b,c,a] are all diﬀerent.
> [a,b,c], [b,c,a], [a,a,b,c,a]; [a, b, c], [b, c, a], [a, a, b, c, a] Because order is preserved, you can extract a particular element from a list without searching for it.
> letters := [a,b,c]; letters := [a, b, c]
> letters[2]; b Use the nops command to determine the number of elements in a list.
> nops(letters); 3 24 • Chapter 2: Mathematics with Maple: The Basics Section 2.6 Expression Manipulation discusses this command, including its other uses, in more detail. Sets
Maple supports sets in the mathematical sense. Commas separate the objects, as they do in a sequence or list, but the enclosing curly braces identify the object as a set.
> data_set := {1, 1, 0, 10, 2}; data _set := {−1, 0, 1, 2, 10}
> unknowns := {x, y, z}; unknowns := {x, y, z } Thus, a set is an expression sequence enclosed in curly braces. Order Maple does not preserve order or repetition in a set. That is, Maple sets have the same properties as sets do in mathematics. Thus, the following three sets are identical.
> {a,b,c}, {c,b,a}, {a,a,b,c,a}; {a, b, c}, {a, b, c}, {a, b, c} For Maple, the integer 2 is distinct from the ﬂoatingpoint approximation 2.0. Thus, the following set has three elements, not two.
> {1, 2, 2.0}; {1, 2, 2.0} The properties of sets make them a particularly useful concept in Maple, just as they are in mathematics. Maple provides many operations on sets, including the basic operations of intersection and union using the notation intersect and union.
> {a,b,c} union {c,d,e}; {a, b, c, d, e} 2.5 Basic Types of Maple Objects > {1,2,3,a,b,c} intersect {0,1,y,a}; • 25 {1, a} The nops command counts the number of elements in a set or list.
> nops(%); 2 For more details on the nops command, see 2.6 Expression Manipulation. Mapping A common and useful command, often used on sets, is map. Mapping applies a function simultaneously to all the elements of any structure.
> numbers := {0, Pi/3, Pi/2, Pi}; numbers := {0, π,
> map(g, numbers); 1 1 π, π } 3 2 1 1 {g(0), g(π ), g( π ), g( π )} 3 2
> map(sin, numbers); {0, 1, 1√ 3} 2 Further examples demonstrating the use of map appear in 2.6 Expression Manipulation and 6.3 Structural Manipulations. Operations on Sets and Lists
The member command veriﬁes membership in sets and lists.
> participants := [Kate, Tom, Steve]; participants := [Kate , Tom , Steve ] 26 • Chapter 2: Mathematics with Maple: The Basics > member(Tom, participants); true
> data_set := {5, 6, 3, 7}; data _set := {3, 5, 6, 7}
> member(2, data_set); false To select items from lists, use the subscript notation, [n ], where n identiﬁes the position of the desired element in the list.
> participants[2]; Tom Maple recognizes empty sets and lists, t...
View
Full
Document
This note was uploaded on 08/27/2012 for the course MATH 1100 taught by Professor Nil during the Spring '12 term at National University of Singapore.
 Spring '12
 NIL
 Math, Division

Click to edit the document details