DISP Mathematics (Scie 1500R)

MAPLE Lab. Tutorial 2 Functions and Plotting Monday January 24.


There is a difference between an expression like $x^3 - 4x^2 + 1$ and the function $f$ that assigns to each $x$ the expression $x^3 - 4x^2 + 1$. This difference is very clear in the MAPLE syntax and you need to be aware of the difference. For functions we often write $x \mapsto x^3 - 4x^2 + 1.$ In MAPLE we make an arrow by typing -> ( a minus sign -, followed by a greater than $>$).

Type the following commands:

> f:= x$\,^{\wedge}$3 - 4*x$\,^{\wedge}$2 + 1; This defines $f$ as an expression.
> g:=x-> x$\,^{\wedge}$3 - 4*x$\,^{\wedge}$2 + 1; This defines $g$ as a function.
> f(2); This gives nonsense.
> subs(x=2, f); This is the way to do it for expressions.
> g(2); This is the way to do it for functions.
> subs(x=a, f);
> g(a);
> (f(x+h) - f(x))/h; More nonsense.
> (g(x+h) - g(x))/h;
> simplify(%);

In this list $g$ is a function, $f$, $g(x)$ and $g(a)$ are expressions and $g(2)$ is a number.

In expressions, the formula is ``static'' and the variable is important, we can change the variable in MAPLE with the >subs( ) command.

A function is a more ``active'' object. It assigns an expression to each $x$ and we can easily change $x$ to other variables, numbers or expressions.

MAPLE has lots of built in functions that it knows about. They include:

sin, cos, tan, cosec, sec, cotan, exp, log, (or ln) sqrt, abs (absolute value) and many more.

Try commands like
> sin(Pi/4); > exp(Pi); >log(a$\,^{\wedge}$2); >exp(%); > abs(-3), > sqrt(5) and so on.


MAPLE has a huge variety of plotting routines available. To see them all type >with(plots);. Usually one doesn't want to see this list. Go back and change the ; to a :. You need to use this command to call up all those sophisticated plotting programs. Just plain graphs are available without it. You can plot both expressions and functions but the commands are slightly different.

Type the following commands:

> plot(f, x= -3..3); Here $f$ is an expression that involves $x$. You give the range of $x$ you want with x= a..b. Just two dots.
> plot(g(x), x= -3..3); Here we make $g(x)$ an expression like $f$.
> plot(g, -3..3); Here g is a function so we don't specify the variable.

We can plot two (or more) functions on the same graph by making a set of expressions (or functions). We do this with curly brackets $\{.\}$. Thus,
> plot({f, 3*x$\,^{\wedge}$2}, x = -3..3);

We can make parametric plots (remember the lecture from last term!) by using vector notation. In MAPLE vectors (and other lists are made with square brackets $[.]$.

> plot([sin(2*t), cos(3*t), t=0..2*Pi]); Experiment with other values than 2 and 3.

You can animate your graphs: Try the following simple animation:
> animate(t*x$\,^{\wedge}$2,x=-1..1,t=1..2,frames=30);

To view an animation, you must click on the plot and then on the play button.


You can program in MAPLE. One way to do this is with a procedure. This begins with proc( ) and one fills in the variable(s) that one needs inside the brackets. It ends with end;. One can insert conditions in the procedure with if ... fi (think of them like brackets).

Complicated functions that are defined by two or more expressions need this format. Try the following examples:
>G:= proc(x) x$\,^{\wedge}$2 +2*x - 3 end;
>plot(G, -4..4);
>H:= proc(x) if x<=0 then 2*x+1 else x$\,^{\wedge}$2 + 1 fi end;
>plot(H, -4..4);
>K:= proc(x) if x < -2 then x+3
    elif x <= 2 then 5 - x$\,^{\wedge}$2
    else 3-x fi end;

>plot(K, -4..4);

Use the Return key to put commands on several lines, and then Enter after the ;



Before you start these exercises type restart.

1. Define the function $f(x) = x^3 -3x^2 +1$.
Write the MAPLE commands here: $>$

2. Plot $f(x)$ on the interval $[-6, 6]$. Estimte (as best you can) the places where $f(x) = 0$.
$x_1 = \hfill, x_2 = \hfill, x_3 = \hfill.$

3. Plot $f(x)$ on the interval $[-1, 3]$. Estimte (as best you can) the places where $f(x) = 0$.
$x_1 = \hfill, x_2 = \hfill, x_3 = \hfill.$

4. Solve the equation $f(x) = 0$ using fsolve
$x_1 = \hfill, x_2 = \hfill, x_3 = \hfill.$

5. What does the following MAPLE command do?
> f_1:= proc(x) f(x-1) end;
If you are not sure, type it and then graph both $f$ and $f_1$ on $[-2,4].$

6. What MAPLE commands would you use to get a function whose graph is the one for $f$ reflected about the $y$-axis? the $x$-axis?


7. Type the commands > g:= x-> sin(x); > h:= x->x$\,^{\wedge}$2;
Plot $f$ and $g$ on the same axes and on the interval $[-2,2]$.
Estimate the places where $g(x) = h(x)$.
$x_1 = \hfill , x_2 = \hfill.$

8. Type fsolve(g(x) = h(x), x); and write what MAPLE responds here...

9. Plot $f$ and $g$ on the interval $[-0.5, 0.5]$. Estimate the place in this interval where $g(x) = h(x)$.
$x_1 = $

Type fsolve(g(x) = h(x), x, -0.5..0.5); and enter what MAPLE responds,
$x_1 = $

10. Use a parametric plot for $x= \sin(3t), y= \cos(5t)$ on $[0,2\pi]$. How many times does the curve intersect itself?

Tony Thompson