Up to Main Lab Page | Next Lesson - Plotting Functions | Previous Lesson - Expressions |
Topics for this Lab: | Standard Maple Functions | Composition of Functions | Piecewise Functions | Special Points | Unapply |
---|
Expressions are a useful tool, however they can become confusing as the variables all are global. Changing x changes the value of any expression involving x. This is not usually how we want things to behave.
We really want to be able to define a mathematical function and use the f(x) notation.
To do this we use the -> operator.
This tells Maple to define the function f(x) = x^2+3*x+4, the global value of x is
irrelevent. Try
> f := x -> x^2+3*x+4;
> x:=7;
> f(2);
> f(n);
Calculus Functions: | |
---|---|
exp | the exponential function: exp(x) = sum(x^i/i!,i=0..infinity) = x -> E^x |
ln | natural logarithm (logarithm with base E = 2.71828...) |
log | logarithm to arbitrary base |
log10 | log to the base 10 |
max, min | maximum/minimum of a list of real values |
sqrt | square root |
The trigonometric functions: | sin, cos, tan, sec, csc, cot. | |
---|---|---|
The hyperbolic functions: | sinh, cosh, tanh, sech, csch, coth | |
The inverse trigonometric functions: | arcsin, arccos, arctan, arcsec, arccsc, arccot, arctan. | |
The inverse hyperbolic functions: | arcsinh, arccosh, arctanh, arcsech, arccsch, arccoth. |
Complex Functions: | |
---|---|
argument | argument of a complex number or expression |
conjugate | conjugate of a complex number or expression |
abs | absolute value of real or complex argument |
Integer functions: | |
---|---|
binomial | binomial coefficients: binomial(n,r) = n!/(r!*(n-r)!) |
ceil | ceil(x) = smallest integer greater than or equal to x |
factorial | the factorial function factorial(n) = n! |
floor | floor(x) = greatest integer less than or equal to x |
round | round(x) = nearest integer to x (round(.5) = 1) |
signum | sign function for real and complex expressions |
trunc | trunc(x) = nearest integer from x in the direction of 0 |
You can use Maple's help to find the exact syntax of these functions (though most of them are obvious). To use Maple's help type in the word and press control F1, or use the keyword search or browser from the help menu.
The last question shows that we must be careful about function domains in Maple.
Given two functions f and g, we may define f composed with g by using the @ symbol.
> f:=x->sqrt(x);
> g:=x->sin(x);
> (f@g)(x);
Note the brackets around f@g.
f(x) | = { | x | if x < 0 |
x2 + 1 | if x > 0 |
piecewise
function to allow you to define piecewise
functions.
NOTE: piecewise
only works in version 4 or above of Maple. In
version 3 you must use the Heaviside
function to define piecewise
functions.
In order to define ranges you may use any of the following symbols:
Symbol | Syntax | Explantion |
---|---|---|
> | x > a | Values of x which are greater than a |
< | x < a | Values of x which are less than a |
>= | x >= a | Values of x which are greater than or equal to a |
<= | x <= a | Values of x which are less than or equal to a |
<> | x <> a | Values of x which are not equal to a |
and | Intersection of two ranges | |
or | Union of two ranges |
f(x) | = { | x | if x < 0 |
x2 + 1 | if 0 <= x < 1 | ||
x2 | Otherwise |
f(x)
= {
ex
if x < 0
sin2(x)
if 0 <= x < PI
sqrt(cos(x))
Otherwise
Certain functions have special values defined at particular points. For example
f(x) | = { | 1 | if x = 0 |
x/x | otherwise |
We can define as many points as we like in this way.
unapply
.
unapply turns an expression into a function.
The syntax is unapply(a, x), where a is an expression and x is the variable in
the definition of a which is to be made into a free variable.
> x:='x';
> a:=x^2;
> f:=unapply(a,x);
> a;
> x:=2;
> a;
> f(y);
> f(4);
Note that x must be undefined when unapply is executed.
The following will generate an error.
> a:=x^2;
> x:=2;
> f:=unapply(a,x);
So will
> a:=x^2;
> x:=c+1
> f:=unapply(a,x);
However the following is OK.
> a:=x^2;
> x:=c+1
> f:=unapply(a,c);
It is always possible to turn a function into an expression by assigning it.
That is, if f is a function then f(x) is an expression.
> f:=x->x^2;
> a:=f(z);
Now try
> a;
> z:=2;
> a;
> f(5);
Up to Main Lab Page | Next Lesson - Plotting | Previous Lesson - Expressions | Top of this Lesson |