This preview shows page 1. Sign up to view the full content.
Unformatted text preview: 7 Arrays are not limited to two dimensions, but those of higher order are more diﬃcult to display. You can declare all the elements of the array as you deﬁne its dimension.
> array3 := array( 1..2, 1..2, 1..2, > [[[1,2],[3,4]], [[5,6],[7,8]]] ); array3 := array(1..2, 1..2, 1..2, [ (1, 1, 1) = 1 (1, 1, 2) = 2 (1, 2, 1) = 3 (1, 2, 2) = 4 (2, 1, 1) = 5 (2, 1, 2) = 6 (2, 2, 1) = 7 (2, 2, 2) = 8 ]) Maple does not automatically expand the name of an array to the representation of all elements. In some commands, you must specify explicitly that you want to perform an operation on the elements. 30 • Chapter 2: Mathematics with Maple: The Basics Suppose that you want to deﬁne a new array identical to pwr, but with each occurrence of the number 2 in pwrs replaced by the number 9. To perform this substitution, use the subs command. The basic syntax is subs( x =expr1, y =expr2, ... , main_expr ) Note: The subs command does not modify the value of main_expr. It returns an object of the same type with the speciﬁed substitutions. For example, to substitute x + y for z in an expression, do the following.
> expr := z^2 + 3; expr := z 2 + 3
> subs( {z=x+y}, expr); (x + y )2 + 3 Note that the following call to subs does not work.
> subs( {2=9}, pwrs ); pwrs You must instead force Maple to fully evaluate the name of the array to the component level and not just to its name, using the command evalm.
> pwrs3:=subs( {2=9}, evalm(pwrs) ); 11 1 pwrs3 := 9 4 8 3 9 27 This causes the substitution to occur in the components and full evaluation displays the array’s elements, similar to using the print command.
> evalm(pwrs3); 2.5 Basic Types of Maple Objects • 31 11 1 9 4 8 3 9 27 Tables
A table is an extension of the concept of the array data structure. The diﬀerence between an array and a table is that a table can have anything for indices, not just integers.
> translate := table([one=un,two=deux,three=trois]); translate := table([two = deux , three = trois , one = un ])
> translate[two]; deux Although at ﬁrst they may seem to have little advantage over arrays, table structures are very powerful. Tables enable you to work with natural notation for data structures. For example, you can display the physical properties of materials using a Maple table.
> earth_data := table( [ mass=[5.976*10^24,kg], > radius=[6.378164*10^6,m], > circumference=[4.00752*10^7,m] ] ); earth _data := table([mass = [0.5976000000 1025 , kg ], radius = [0.6378164000 107 , m], circumference = [0.4007520000 108 , m] ])
> earth_data[mass]; [0.5976000000 1025 , kg ] In this example, each index is a name and each entry is a list. Often, much more general indices are useful. For example, you could construct a table which has algebraic formulæ for indices and the derivatives of these formulæ as values. 32 • Chapter 2: Mathematics with Maple: The Basics Strings
A string is also an object in Maple and is created by enclosing any number of characters in double quotes .
> "This is a string."; “This is a string.” They are nearly indivisible constructs that stand only for themselves...
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