Jason Rennie's Maple Page
Useful Constructs
- Including Libraries - e.g. "with(plots):"; using a colon suppresses output---otherwise a list of all functions in the plots library will print
- Assignment/Labels - an expression may be named with a label; labels may only contain letters, numbers and the underscore and must start with a letter; e.g. "q := x^2+5;"
- Substitution - assign a value to a variable in an expression; e.g. "subs(x=1,p);"
- Function - use "->" to separate argument from expression; use a tuple to define a function of multiple arguments; e.g. "f := x -> x^2+1;" or "g := (x,y) -> x*y;"
- Compound Function - e.g. "f := x -> if x>=0 then x+3 else 3-x fi;"
- Plot - use curly braces to specify multiple functions; e.g. "f:=x->x^2; plot(f,-2..2)" or "plot({x^2,sin(x)},x=-2..2)"
- 3-D Plot - e.g. "g:=(x,y)->x*y; plot3d(g,-2..2,-2..2)" or "plot(x*y,x=-2..2,y=-2..2)"
- 3-D Curve - e.g. "with(plots); spacecurve([cos(t),sin(t),t],t=0..4*Pi);"
- Clearing a Variable - when you want to un-set or free a variable; e.g. "v := 'v';"; to undefine all variables, use "restart;"
- Derivative of a Function - use "D"; e.g. "f:=x->x^2; D(f);"
- Value of the Last Expression - use "%"; e.g. "with(student): leftsum(1/t,t=1..2,10); value(%);"; can also use double-quotes; two double-quotes refer to two expressions back, three double-quotes to three expressions back, etc.
- Tables & Arrays - A table is an associative array; an array is the usual array
Useful Functions
Notes
- Maple makes a distinction between (mathematical) functions and
expressions. Many (programming language) functions in the Maple
library deal with expressions, not functions. Note that it is easy to
convert a function to an expression, just apply it to a variable name.
e.g. if "f:=x->x^2" then "f(x)" is an expression.
- An equals-sign without a preceeding semicolon marks an
equation; nothing gets assigned without a semicolon.
- Parentheses
- Parentheses () are used for grouping algebraic expressions
- Brackets [] are used for defining ordered lists (and, by extension, matrices)
- Braces {} are used for defining sets
- No delimiters are used to define a sequence; e.g. "a,b,c;" is a sequence
- Capitalization of library function is used to denote the "inert" version. e.g. "Diff(x^2,x)=diff(x^2,x);"
- For numerical evaluation of integrals, use an "Int" inside an "evalf"; e.g. "evalf(Int(sqrt(1+x^10),x=0..1));"
- Use the hash character "#" to create a comment
- linalg seems to be the standard library for linear algebra manipulations
- To call a function within a library without first loading that library, use the long form of the name, "libname[funcname](..)"; e.g. "linalg[trace]([[a,b],[c,d]]);"
Links
Last modified: Mon Dec 19 18:06:43 EST 2005