Creating your own Mathematical Functions
We have been working with expressions so far. Maple also supports the mathematical notion of a function. To define a function, you must specify a rule for going from one number to another. Consider the following commands:
f := x^2; |
f := x2 |
This defines f to be an abbreviation for the expression x2. |
f := x -> x^2; |
f := x -> x2 |
This defines f to be a function, such that f(x) = x2. |
f(3); f(t); |
9 t2 |
The function works as standard notation. |
| A common mistake is to write f(x) := x^2;. This does not define a function. Instead, it makes the four characters on the left an abbreviation for the three characters on the right. |
Functions are often more useful than expressions. However, many Maple commands (for example, diff) expect an expression as input. If f := x -> x^2, then diff(f,x); doesn't work. However, diff(f(x),x); will work, since f(x) produces the expression x2.
To convert an expression into a function, use the unapply command.



