1 EXPRESSIONS AND FUNCTIONS.
There is a difference between an expression like and the function that assigns to each the expression . This difference is very clear in the MAPLE syntax and you need to be aware of the difference. For functions we often write In MAPLE we make an arrow by typing -> ( a minus sign -, followed by a greater than ).
Type the following commands:
> f:= x3 - 4*x2 + 1; This defines as an expression.
> g:=x-> x3 - 4*x2 + 1; This defines 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 is a function, , and are expressions and 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 and we can easily change 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(a2); >exp(%);
> abs(-3), > sqrt(5) and so on.
2 PLOTTING.
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 is an expression that involves .
You give the range of you want with x= a..b. Just two dots.
> plot(g(x), x= -3..3); Here we make an expression like .
> 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*x2}, 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*x2,x=-1..1,t=1..2,frames=30);
To view an animation, you must click on the plot and then on the play button.
3 MORE COMPLICATED FUNCTIONS
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) x2 +2*x - 3 end;
>plot(G, -4..4);
>H:= proc(x) if x<=0 then 2*x+1 else x2 + 1 fi end;
>plot(H, -4..4);
>K:= proc(x) if x < -2 then x+3
elif x <= 2 then 5 - x2
else 3-x fi end;
>plot(K, -4..4);
Use the Return key to put commands on several lines, and then Enter after the ;
4 EXERCISES
NAME STUDENT #
Before you start these exercises type restart.
1. Define the function
.
Write the MAPLE commands here:
2. Plot on the interval . Estimte (as best you can) the places
where .
3. Plot on the interval . Estimte (as best you can) the places
where .
4. Solve the equation using fsolve
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 and on
6. What MAPLE commands would you use to get a function whose graph is the
one for reflected about the -axis? the -axis?
7. Type the commands > g:= x-> sin(x); > h:= x->x2;
Plot and on the same axes and on the interval .
Estimate the places where .
8. Type fsolve(g(x) = h(x), x); and write what MAPLE responds here...
9. Plot and on the interval . Estimate the place in this
interval where .
Type fsolve(g(x) = h(x), x, -0.5..0.5); and enter what MAPLE responds,
10. Use a parametric plot for
on . How
many times does the curve intersect itself?