Next: Statements: AssignmentConditional, Up: Introduction Previous: Expressions: SumsProducts,

Indexed names and Functions

Maple has two kinds of variables or names as Maple calls them. There are strings like x, sin, Pi, which are of type string and indexed names or subscripted variables like which are of type indexed. These examples are input A[1], A[i,j], A[i][j] in Maple. Most functions in Maple accept both kinds of variables. The Maple type name means either a string or a subscript. Example

=-1.00.5plus##1`##1=12=^^M=12 > type(a,string); true

> type(a,name); true

> whattype(A[1]); indexed

> type(A[1],indexed); true

> type(A[1],name); true

plusplus -100 plus If is an indexed name, then the nops function returns the number of indices, and the op function returns the 'th index. Also returns the name of the index. Example

=-1.00.5plus##1`##1=12=^^M=12 > nops(A[i,j]); 2

> op(1,A[i,j]); i

> op(0,A[i,j]); A

> nops(A[i][j]); 1

> op(1,A[i][j]); j

> op(0,A[i][j]); A[i]

plusplus -100 plus Functions work very similarly to indexed names. The syntax for a function call is

where is the name of the function, and are the arguments. The nops function returns the number of arguments, and the op function returns the 'th argument. Also op returns the name of the function. Example

=-1.00.5plus##1`##1=12=^^M=12 > nops(f(x,y,z)); 3

> op(1..3,f(x,y,z)); x, y, z

> op(0,f(x,y,z)); f

plusplus -100 plus We can now create and pick apart any Maple formula. Exercise 6 asks you to write a Maple program that picks apart a Maple formula. We conclude here with some examples showing how this can be done interactively.

=-1.00.5plus##1`##1=12=^^M=12 > f := sin(x[1])^2*(1-cos(Pi*x[2]));

2 sin(x[1]) (1 - cos(Pi x[2]))

> whattype(f); *

> op(1,f); 2 sin(x[1])

> op(1,op(1,f)); sin(x[1])

> op(1,op(1,op(1,f))); x[1]

plusplus -100 plus



Next: Statements: AssignmentConditional, Up: Introduction Previous: Expressions: SumsProducts,


Klaus Steinberger
Mi Apr 13 12:51:51 MDT 1994