Back to Maple Tutorial Table of Contents
A function is a special type of variable that stores an equation. This equation can be evaluated at different values.
A function allows you to evaluate at a given number. A variable is a static constant. If you want Maple to remember a number for you, use a variable. If you want to store an equation, use a function.
The procedure is relatively the same as defining a variable.
> f:=x->x^2;
![]()
Notice the "x->". This is typed by pressing x, the hyphen key, and the greater than sign. This tells Maple which variable is the input variable.
Another example:
> g:=y->y^3;
![]()
> h:=theta->sin(theta)^2+theta;
![]()
> f(2);
![]()
> g(f(2));
![]()
> h(Pi);
![]()
> h(Pi/4);
![]()
Unlike a variable, you cannot use it's name to view it. You must evaluate it at an unknown variable. Most of the time, you will want to evaluate it at the variable you used when you defined it.
Example:
> z:=a->a^2+a;
![]()
> z(a);
![]()
Using this method, you can find the value of a function at some other variable.
> z(b);
![]()
You can also insert expressions:
> z(theta+2);
![]()
Note that other procedures with functions are identical to those of variables. Example:
> h(x);
![]()
> h:='h';
![]()
> h(x);
![]()
> f:=(x,y)->x^2+y^3;
![]()
> f(2,3);
![]()
Note the (x,y). This tells Maple that the function will have two variables. As above, separate the two variables with a comma. You must include the parenthesis.
This type of function takes more than one equation and does multiple computations. It's useful if you want to compute different computations with a number. (Example: sin(x), cos(x), and tan(x).)
> g:=x->x^2,x->x^3,x->x^4;
![]()
> g(2);
![]()