> restart;
More About Plotting
In the previous Maple worksheet , Introduction to Maple, you learned basics of Maple syntax and handling of worksheets. In this worksheet we look more closely at Maple's plotting facility. We are going to use a lot of plotting in the future.
Fancier Plots. Plotting Families of Functions.
There are many options that can be added to the basic " plot " command to enhance your plots. For example:
> plot(t^2, t=0..3,color=blue,thickness=2,labels=["time in seconds","velocity in feet"]);
>
The command "
labels=[...]
" allows you to label the axes on your graph. The commands "
color=blue
", "
thickness=2
" specify the color and the thickness of your graph. (The higher the number, the thicker the graph). These and many other options are especially helpful when you want to graph several functions in one coordinate system. Suppose you want to study the family of functions
for different values of
. The simplest way is to graph a few of them and look at their graphs. We can graph several functions in one coordinate system by entering formulas for the functions under the "
plot
" command together with the common range. For example:
> plot({sin(x), sin(2*x), sin(3*x)}, x=-Pi..Pi);
>
As you see, we put the functions we wanted graphed inside the curly brackets {...} , which in Maple denotes the set of elements. Maple drew the three functions above. But which is which? Without knowing that, we cannot really analyze the situation. One of the ways of distinguishing between your graphs is to enter functions under the " plot " command not as a set , but as a list . A list in Maple is always denoted by square brackets [....] . The difference between a set and a list is that in the list the order of elements matters, while in the set it does not. We put our three functions as a list and assign a list of colors to them, so we know what color corresponds to which function.
> plot([sin(x),sin(2*x),sin(3*x)], x=-Pi..Pi, color=[blue,red,black]);
>
Now the graph of the first function
on our list is in blue, the second in red and so on. Instead of using colors, you could differentiate between your graphs by assigning a list of thickness values to your functions, e.g.
thickness=[1,2,3]
, or different line styles, e.g.
linestyle=[1,2,3]
. The latter command will produce graphs drawn with different broken lines.
Plotting Numerical Data
As we already know, functions are often given numerically, through a table of values, rather than by formulas. Suppose we have the following data regarding the population of a town,
, in thousands,
years after Jan 1, 1990. The first coordinate stands for t, the second coordinate for
.
(0,15.1), (1, 16), (2, 16.9), (3, 18), (4, 18.9), (5, 20), (6, 21.4), (7, 22.7).
Is the growth of the town's population approximately exponential? We know that to answer this question we have to check the ratios between values of
corresponding to equally spaced values of
.
> 16/15.1, 16.9/16, 18/16.9, 18.9/18, 20/18.9, 21.4/20, 22.7/21.4;
>
The ratios are not exactly the same, but they are all relatively close to 1.06. This means that the population of the town has been increasing at approximately 6% per year. The approximation is pretty good. The difference between the actual ratios and 1.06 does not exceed 0.01=1%. In this context, 1% of the population means a couple of hundred people. Hence, we can safely say that the growth of the population has been approximately exponential with the growth factor 1.06. With the initial population of 15.1 thousand, the formula which describes approximately the growth of the town's population is
.
We would like to plot the numerical data and compare it with the graph of the exponential function. To plot the numerical data we first define a list of the consecutive data points. As mentioned above, lists in Maple are built using the square brackets [..] .
> s := [[0,15.1],[1,16],[2,16.9],[3,18],[4,18.9],[5,20],[6,21.4],[7,22.7]];
>
The command to plot a list of points is " pointplot ". Similarly as the command " display " that we use below, it is a part of a package of plotting commands called "plots". When you start Maple it loads into the computer's memory only the so called kernel , which contains basic functions and commands. More advanced commands are contained in so called packages which have to be loaded when you need them. The package "plots" is loaded by the command " with(plots) ". If you type " with(plots); " ending with a semicolon, Maple will list all the commands in the package. If you want Maple to load the package, but don't care to see its content end your command with a colon " with(plots): " Since this is our first time with the package "plots" we are curious to see its content.
> with(plots);
Among the commands we see " pointplot " that is used to plot a list of points, and the command " display ", which allows you to plot graphs of different types or over different ranges in one coordinate system. Having loaded the package, we can use commands contained in it.
> pointplot(s);
In order to compare the graph with the graph of the corresponding exponential function, we shall use the " display " command to plot the two graphs in one coordinate system. It is a good idea to first label the two graphs that we want plotted. Observe how we use " := " to define the meaning of " a " and " b ".
> a :=pointplot(s):
> b :=plot(15.1*(1.06)^x, x=0..7):
> display([a,b]);
>
Observe that the first two commands end with a colon and not a semicolon to prevent Maple from attempting to print each of the graphs separately before the " display " command.
Homework Problems
Note. Remember to give your explanations in complete sentences and to type them in your homework worksheet using Maple's text mode.
Problem 1.
Consider the family of exponential functions
for various values of
. The proper syntax for
is
exp(k*x)
. Again:
is entered on the command line as
exp(k*x)
and not anything else. Similarly, say,
is entered as
exp(a*b*t+5)
etc.. Follow the syntax carefully!
(a) Plot a few funtions in the family, say for
, in the same coordinate system to see the effects of
on the exponential. Make sure you know which graph is which by assigning a list of colors. In order to see the graphs clearly, choose a range for x that is not too large. For example, x between -2 and 2.
(b) Describe in words the effect of the parmeter
on the graph.
Problem 2.
Consider the family
, where
is a parameter.
(a) Plot the functions for various values of a, e.g. a=0 ,1, -1, and for x between -3 and 3, in the same coordinate system. Distinguish between the graphs by assigning a list of colors or thickness values.
(b) Descibe in words the effect of
on the graph.
Problem 3. The amount of a certain drug in a patient's blood t hours after the injection, in micrograms per cc, is measured to be as follows:
(0, 80.1), (2, 63), (4, 50.1), (6, 40.6), (8, 32.4),
where the first coordinate denotes time t, the second the amount of drug left, Q.
(a) Is the drug decaying in an approximately exponential fashion?
(b) Find the approximate exponential formula for Q in terms of t. ( Hint: Observe that the changes in t above are every 2 units. Make sure that you get the right base for your exponential.)
(c) Plot the data points.
(d) Plot in one coordinate system both the data points and the graph of the approximating exponential function. Do they appear close?
Note. If you execute the restart command in your homework worksheet, do not forget to reload the with(plots); package before using the pointplot and the display commands!
MTH 141 Maple Worksheets written by B. Kaskosz and L. Pakula, Copyright 1998
Last modified August 1999.
>