Home Page

   Introduction

   Topics with
Brief Descriptions

1 Numerical Calculations and Approximations
2 Algebraic Calculations
3 Graphing
4 Solving Equations
5 Functions
6 More on Graphing
7 Problems

MAPLE Learning
Exercises

 

Topic 5 – Functions: Defining, Evaluating and Graphing

Section 1: Defining and Clearing a Function in Maple
Section 2: Evaluating a Function
Section 3: Solving Equations involving Functions
Section 4: Graphing a Function

Material originated in 2000 by Seattle Central Community College
 and available for general usage.
Liberally edited by Anita Johnston, 2002

Let’s begin.
> restart;

Section 1: Defining and Clearing a Function in Maple
To distinguish a function from an expression, Maple requires special notation when defining a function.  For example, the function f(x) = math problem is defined as:
> f:=x->cos(Pi*x)+3;  

Take note of the syntax here. It is absolutely necessary to type the "arrow"   - >  made by typing a "minus sign" and a "greater than" symbol.  Maple will not define a function if you type   f(x):=cos(Pi*x)+3 ;   

Below is a comparison of an expression and a function.  Note the difference in syntax and how Maple returns the output for each.
> y:=(x + 2)/(x^3 + 5*x + 2);
> f:=x->(x + 2)/(x^3 + 5*x + 2);

Functions always require an arrow when typing in; Maple should also have an arrow in its output.  Always check the output for the arrow to confirm that you have in fact defined a function.

Practice Problem 1
E
nter the function h(x) = math problem  in the workspace below.
Solution:
> h:= x-> x^3*sin(2*x+1);

math problem

Once you have defined a function, Maple will remember that function during your entire working session.  If you want to overwrite the function with a new definition, you simply retype the definition.  For example, if you want to replace the function f(x) above with ln(cos 5x), type:
> f:=x->ln(cos(5*x));

We can confirm the current value for the function  f(x) :
> f(x);

If you want to clear the function f(x) without redefining it, type:
> f:='f';

It's always a good idea to clear your functions when you start a new problem. Alternatively you can use restart to clear everything from memory.

Section 2: Evaluating a Function
Once a function has been defined, you can evaluate it at various values or literal expressions using function notation.  It's always a good idea to clear the function name first before entering a new function.
> f:='f';
> f:=x->3*x+x^2;
> f(-1);
> f(2+sqrt(5));
> evalf(f(2+sqrt(5)));
> f(x+4);
> simplify(%);
> (f(x+h)-f(x))/h;
> simplify(%);

If more than one function is involved, composing functions is easy to do.
> g:=x->cos(x)+1;
> f(g(Pi/3));
> j:=x->g(f(x));
> j(x);

Practice Problem 2
D
efine the function math problem  then have Maple calculate

s(2),and s(t-3) and s(t) - s(3) and simplify your results. Don't forget the arrow notation!
Solution:
> restart:
> s:= t-> (3 + t^2)/(sqrt(3*t+1));

math problem

> s(2);
                                               math problem

> s(t - 3);

                                 
math problem

> simplify (%);

math problem

> s(t) - s(3);

math problem

> simplify(%);

math problem

Notice that if you define a function, there is no need to evaluate the function using the "subs" command like you do with expressions. 

Section 3: Solving Equations involving Functions

Once your function is defined, you can solve equations with functions either exactly or approximately:
>
g:='g';
> g:=t->t^3-6*t^2+6*t+8;
> solve(g(t)=0,t);
> fsolve(g(t)=0,t);

Section 4: Graphing a Function
The plot function works the same for functions:
>
h:='h';   y:='y';  x:='x';
> h:=x->x*exp(-x);
> plot(h(x),x=-1..4,y=-2..1);

Several functions can be graphed simultaneously just at we did for expressions.  Consider the function   math problem.  Below we graph this function along with the horizontal shifts math problem , math problemand math problem . Can you identify each ?
> f:=x->2/(x^2+1);
> plot([f(x),f(x+1),f(x-3),f(x-6)],x=-5..10,y=-1..3);

Practice Problem 3
D
efine the functions  math problem  and  math problem  then do the following.
a) Plot a graph that shows both functions g(x) and h(x). Experiment with different values for domain and range.
b) Estimate the coordinates of the point of intersection of these two graphs by using left mouse-button click.
c) Use fsolve( ) to solve the equation g(x)=h(x). How does the solution of this equation relate to your answer to part (b).
Solution:
a) > restart:
> with(plots):
Warning, the name changecoords has been redefined
> g:=x->5*exp(-0.5*x);

math problem

> h:=x->x+1;

math problem

> plot([g(x),h(x)],x=-5..5,y=-20..20);

math problem

> plot([g(x),h(x)],x=1..2,y=1..4);

math problem

b) An estimated value for the point of intersection is (1.5, 2.4).

c)  > xval:=fsolve(g(x)=h(x),x);

math problem

The solution to g(x)=h(x) is the x-coordinate of the point of intersection of g(x) and h(x). To find the corresponding y-coordinate of the intersection point evaluate either g(x) or h(x) at this value.
> g(xval);

math problem

> h(xval);

math problem

The solution found by fsolve( ) is the exact value of the estimated point of intersection in part b).  It is a solution to the system of equations.