> restart;
A First Look at Maple, Part II
Functions, expressions, and graphs
In this worksheet, we explore the notation and use of functions and expressions in Maple and give some introductory examples of graphs and their use.
Functions and Expressions Maple draws a clear distinction between functions , which it understands to be rules which assign output values to input values, and expressions , which it uses as a very literal shorthand. For example, the command
> g:=u->u^2-5/(u-3);
>
defines a function called g by the formula indicated. The name of the variable is irrelevant; Maple understands that any input value is to create an output value according to the formula. For example, consider these commands and their responses.
> g(-4);g(-4.0);g(2.8);g(x);g(a+2*b);
Maple has listed the various values of the function g which result from different inputs. Note that the system is quite happy with either numbers or symbols as input. Also note how the appearance of the output in the first three commands is determined by the nature of the input. The input "-4" is read as an integer and hence the output is given as a quotient of integers rather than in decimal form; the inputs "-4.0" and "2.8" are read as floating-point decimals, and so the output appears the same way. Indeed, the zero after the decimal point is not even necessary in the second input, for Maple will read "-4.0" and "-4." -- note the decimal point in the latter -- as having the same meaning.
A common issue which arises when substituting values of a variable into a function is that of the domain of the function. If an input is not in the domain of a certain function, then the output of the function will not be defined. The function g used above can illustrate how this appears.
> g(3);
Error, (in g) division by zero
Maple has warned us, in detail, about an illegal operation. Most of its error messages are, like this one, quite informative, telling you what sort of problem has occurred and where. These descriptive error messages are a very helpful feature of the system.
In contrast to the use of a function which has been demonstrated above, let's see how Maple views a so-called expression . Compare the following commands and responses carefully to those used with the function g above.
> k:=u^2-5/(u-3);
Maple understands the symbol k to be a literal shorthand for the expression on the other side of the equals sign. Formulas like " k (-4)" and " k ( x )" are meaningless to Maple. To substitute a value or a variable in place of u in k , a direct command to do so must be given.
> subs(u=x,k);
> subs(u=-4,k);
> subs(u=3,k);
Error, division by zero
To evaluate expressions, the main tools are the " eval " and " evalf " commands. Another command which is useful in other contexts, namely " value ", will not be needed here and will be addressed in a later worksheet. Execute the commands below and see what you can learn about how to evaluate expressions.
> evalf(eval(k,u=5));
> eval(20*Pi*%);
> eval(k,u=13);
> evalf(5*Pi*%);
>
Graphing Maple has excellent abilities and tools for the production of two-dimensional and three-dimensional graphs. We will merely touch on the subject here and then devote the next worksheet to many more topics involving graphing.
We begin by producing a simple graph. We first define a function and then give a plotting command.
> j:=t->2.5*t^4/((t^2+1)^2);
> plot(j,-3..3);
>
You specify the interval for the independent variable, and as a default, Maple adjusts the vertical interval automatically. If you wish to choose the vertical interval yourself, you can do so.
> plot(j,-8..8,-2..5);
>
On both of the graphs above, and indeed on any graphical object, it is easy to change the size of the picture. Click once on the graph, and then click-and-drag on a border of the "box" to size the graph as you wish. Try this above.
It is also possible to plot using an expression instead of a function. Since the system reads the expression literally, as described above, it is necessary to give the name of the variable in the expression when describing the domain of the plot. For instance, using the expression k which was defined above, we have the following.
> k:=u^2-5/(u-3);
>
> plot(k,u=3.1..5);
>
A question you should consider now is this: With u = 3 outside the domain of the expression k -- attempting to use that value results in a division by zero -- what might happen if we tried to graph the expression across an interval that includes 3? You will encounter many situations like this one in your precalculus course, and we'll need to see more about what the graph should look like (and, perhaps, how it actually appears).
It is possible to put several graphs on one picture and to choose the color of any graph. We illustrate this briefly by plotting the line
y
= 1.5
x
+ 30 and the parabola
on one graph below.
This also illustrates another plotting option, that of putting the variable expression directly into the plotting command, skipping any use of Maple expressions or functions.
> plot([1.5*x+30,65-x^2],x=-10..8,color=[blue,green]);
>
As you can probably imagine from the last examples, there are many ways to give the commands for plotting. Once again, the "Help" menu is extremely informative, and more topics in graphing will be pursued in the next worksheet.
Homework Problems As usual, you should do these problems in a Maple worksheet. Include full text explanation, description of steps, and comments on results.
Problem 1.
(a) Plot the line
for a domain of your choosing, but including
x
= 0.
(b) By adjusting your choice of the horizontal and/or vertical intervals used, plot the same line,
but in such a way that it appears to be nearly horizontal.
(c) By adjusting your choice of the horizontal and/or vertical intervals used, plot the same line,
but in such a way that it appears to be nearly vertical.
(d) Comment on the importance of graphs having carefully labeled axes, and describe how a
poorly labeled graph in a real-world situation could be very misleading. Could you describe
a situation in which someone might intentionally attempt to mislead others through the
appearance of a graph?
Problem 2.
On one set of axes, and in two different colors, plot the graphs of the equations
and
. By looking at the graph, focusing on certain regions if necesssary, make an estimate by eye of the coordinates of any and all points of intersection of the two graphs. It's a good idea to "zoom" in on interesting points of the graph by adjusting the horizontal and vertical regions in your plot, as was done in an example above.
Problem 3.
Use appropriate Maple commands to give an algebraic solution of the system in Problem 2. Do your values for the variables match the estimates you made in Problem 2? Can you think of a way to check these answers in the original system by using appropriate Maple commands?
Problem 4.
(a) Use three different command methods to plot a graph of
on the interval from
x = 1.4 to x = 5.7. In one method, define a function and plot it; in another, define an expression
and plot it; and in the third, use the variable expression directly, without defining a Maple
expression or function.
(b) Find the lowest value of y which occurs on your graph, and the corresponding value of x .
(c) Try some intervals which include x = 0, x = 6, or both, and try to describe what is happening.
(Note: This topic will be addressed again in the next worksheet.)