Math 1350 Calculus I - Lab 1 - Functions and Maple

As you are already aware, there are three different ways a function can be represented: it can be defined by a table, a graph or as an algebraic expression. In this lab we will explore the way these representations can be used in Maple.

Before we begin, you should be aware of the fact that Maple is a computer program designed to perform mathematical tasks. However, Maple does not have the ability to perform the operations that you intend unless you tell it to do so correctly. As with a lot of other software programs, Maple is case sensitive. For example, the plot command uses only lower case letters. If you wish to generate a graph, you must type "plot." If instead, you were to use "Plot", Maple would not recognize the command. You must take care to type in commands in a form that Maple will recognize. Fortunately, Maple has a very powerful help facility on which you can rely.

More often than not, when you don't know how to tell the computer what you want it to do- the help program can guide you through the process. There are two basic means by which you can access help during a Maple session. The more general method is to use the help menu.. The second method is more specific in nature. On the command line, simply type a question mark followed by the name of the command that you are interested in. For example, typing ?plot and then pressing enter would open the help page that talks about the plot command. Even if you are not familiar with the exact command, you can still use this method. If you type a question mark followed by one or two characters, Maple will provide a list of suggested commands which may prove helpful. As you become more acquainted with Maple, you will find that this is the more expedient method of the two.


Part I. Representations of Functions in Maple.

First we will explore how the three different functional representations are given to Maple. Let's begin by looking at a function defined via a table. Maple V has a variety of built-in structures which can be used to store tabular data. Data may be kept in many different kinds of structures, but in this lab we will restrict our attention to the list structure. As the name implies, a Maple list is an ordered set of entries; similar to, say, a shopping list. In our case, the entries in our list would consist of ordered pairs. For example, if we had a table for the values of a function f(t) in terms of the independent variable t, the entries in the list would be the points ( t , f ( t )) . Let's say we had the following table of data:

[Maple OLE 2.0 Object]

We could then get Maple to understand the list by using the following command:

> list1:=[[0,67.38],[1,69.13],[2,70.93],[3,72.77],[4,74.66],[5,76.6],[6,78.59]];

[Maple Math]

What I have done here is used the "list" command. Whenever I want to enter any kind of mathematical text, I must be sure the computer is ready to read the command as a mathematical operation. In order to prepare the computer I use the prompt for Maple input. In all the typing before the command line, I was using text input. When I wanted to switch to Maple input, using my mouse, I dragged the pointer to the Insert menu at the top of the screen. I pulled down on this menu and selected "Maple Input." Note that you can only put a Maple Input line on a completely fresh line- so put your cursor below the bracket on the left before attempting Maple Input. Now, at the start of the next line I will have a little arrow at the beginning of the line. This arrow is called a Maple prompt, it is the computer's way of telling me that what I enter will be read as a mathematical command. Another way you can tell when you're working in the Maple Input mode is that the letters you type on the screen will show up as heavy read letters instead of the typical black letters.

Now, back to the "list" command. In order for the computer to understand that I was giving it a list I had to type the command "list." But just typing "list" wasn't enough. In addition to the list command, I had to give my list a name. So, I named the set of data "list1." So, typing "list1" established a name for my list. Next, I have to tell the computer what data set I want to be called by the name "list1." This is accomplished by using a colon then an equals sign. The symbols ":=" are called the assignment operator. Its your way of telling Maple that the items to the left of the ":=" are the name and the items to the right are the things to be named. You must be careful to use ":=" when assigning values to a variable and not just "=".

After the ":=" I have simply typed each of my ordered pairs enclosed by a set of brackets with commas between each ordered pair. Note also that I enclosed the entire list in a set of brackets- that is so Maple can identify the list.

The semicolon at the end of the command is necessary as well. Maple detects the end of a command by looking for either a colon or a semicolon. If the command is missing this punctuation, Maple will not perform any evaluation because it is not aware that you have reached the end of your command. This can be frustrating to the new user because it will not be apparent what the problem is. If the semicolon were left off the preceding command and enter were pressed, Maple would give you a new line and then wait for further typing. Meanwhile, you could also be waiting for Maple to evaluate the command. Be sure to end your commands with a semicolon!

Notice that after I typed the top line asking it to establish the list the computer typed the next line showing me what it had done.

Now let's go back to the list we were using above. Once the list is defined, we can use Maple to perform various mathematical operations. For example, we could ask Maple to plot the points in the list: the command would be plot(list1,t=0..7);. Notice that when you execute this command, Maple automatically connects the points with straight line segments. In order to generate the figure below, we must slightly modify this command by telling the computer to only plot our points by using the "style=point" at the end of the command. Whenever we use the plot command, we always type "plot" then in parentheses we tell Maple what we want to plot and the input values to use. We will discuss the plot command in more detail in the next section.

> plot(list1,t=0..7,style=point);

[Maple Plot]

Another thing Maple can do with a list is to determine how much the function changes over a given time interval. We could look at the difference in the output values by using the command list1[4]-list1[2];. If we were checking for exponential growth (or decay) we would want to look at the ratio between output values and so we would use list1[4]/list1[2];.

The next way we want to represent functions in Maple is using an algebraic expression. Suppose for example we want to define the functions f(x)=  x2+5. Then we would use the command:

> f:=x->x^2+5;

[Maple Math]

Here we are naming the function f by typing the f to the left of the symbol ":=". To the right of the symbol we have told the computer that the function sends x to x2+5. Note that to get Maple to generate an exponent we use the ^ symbol which is above the 6 on your keyboard. The arrow is generated using the dash key above the "p" then the arrow key from above the period.

One of the handy things Maple can do with a function is to tell us the value of the function for any input. For example, suppose we wanted to know what the value of the function is at x=3.5. Then we simply enter the command "f(3.5);" and the computer will tell us the value as follows:

> f(3.5);

[Maple Math]

We can also generate a graph of our function:

> plot(f(x),x=0..5,title=`My plot of f(x)`);

[Maple Plot]

Note that the single quotes around the title of the graph are not apostrophes but right-hand single quote marks. This character is usually found in the upper left corner of the keyboard, on the same key as the tilde, "~". Maple has the ability to perform many operations besides just evaluating functions and graphing- but we will investigate more of these in future labs.

One comment is in order at this point: Maple distinguishes between functions and expressions. As you know, a function is basically a rule that takes an input value and returns an output value. If we were to make the assignment "f:= x^2 + 5;" as opposed to, say, "f := x->x^2+5;", Maple would view f as being an expression and not a function. The command f(3); would not generate the desired response. Try it. You should always define functions in the manner listed above.

Part II. Generating graphs in Maple V.

Besides tables and algebraic methods we can also use graphs to help in our study of functions. Maple is readily suited to this approach- it is able to graph functions in seconds that would take quite a while to graph by hand. Graphs are generated by using the plot command. As we have seen, Maple can generate graphs based on either tables of data or function definitions. Maple also has the ability to generate graphs displaying more than one function at a time. The basic syntax of the plot command is as follows: plot({function}, x range, y range, options);.

Here's a little more info on each of these elements:

{function} - denotes either a function, a list of data, or a list of functions. The braces are not needed unless you are generating a plot using more than one function or more than one data set.
x range - the range of values that the independent variable may assume in order to generate the graph. The range is specified using the expression x=low..high, where low and high are the left and right endpoints of the interval.
y range - this is an optional argument that is given to the plot command. The argument has the same format as the x range argument only we are now restricting the y values, i.e., y=low..high. Note that if you don't specify a certain y-value Maple will choose one for you.

options - Maple allows you to define several optional arguments. These options include specifying a title for your graph, setting the number of tickmarks on the axes, specifying line styles, etc.

It is often very useful to us to be able to change the x and y values because it allows us to zoom in or out on our graph to get a better idea of the graph's behaviour.

Note : there is nothing special about the letters x and y . If we were plotting a function where time was the independent variable, we would restrict the time domain via t = low .. high. In fact, if you have defined a function as a function of t , you won't be able to generate a graph of the function unless you use t as the domain variable

Example : Plot f(x)=3cos(2x)+4 on the interval [0,4p] . (Note that in Maple we use "Pi" to denote the symbol p .) We enter the command:

> plot(3*cos(2*x)+4,x=0..4*Pi);

[Maple Plot]

One great use for the graphing component of Maple is that it will allow you to find the intersection of two graphs. To illustrate this allow me to use an example:

Example: For what values of x are the functions f(x)=3x and g(x)=x4-1 equal?

We have two methods to obtain a solution: either analytically or graphically.

Solution 1 (analytic): We utilize the Maple procedure "fsolve" . This procedure will give us the numeric solution to our problem. We first define the functions f and g via the commands

> f:=x->3^x;

[Maple Math]

> g:=x->x^4-1;

[Maple Math]

We now tell Maple to find the value(s) of x such that f(x)=g(x):

> fsolve(f(x)=g(x));

[Maple Math]

As with most Maple procedures, there are several optional commands that you can specify when using fsolve. There is another command similar to fsolve that Maple recognizes and that is "solve." The difference between the procedures solve and fsolve is that solve will return an exact answer whenever possible. Usually this is a symbolic rather than a numeric solution.

Solution 2 (graphical): At the beginning of solution 1 we started by identifying our functions f and g. Since they are already in the computer, I don't have to redefine them. This is one of the nice features of Maple- it will remember the last name given to any particular function.

Next we graph these functions on the same set of axes:

> plot({f(x),g(x)},x=-10..10);

[Maple Plot]

This graph gives us some useful information. Although we cannot determine the points of intersection as of yet, the graph does indicate there at least two solutions. We will have to adjust the viewing window in order to find the point(s) of intersection. After some trial and error, we arrive at the graph:

> plot({f(x),g(x)},x=-3..3,y=-3..8);

 [Maple Plot]

Further restricting the plot window reveals that the two solutions are approximately -1.07 and 1.624. However, our original graph also indicated a solution near x=7. By zooming in around x=7 we find the third solution, approximately 7.174. This comparison indicates the relative merits of both methods: fsolve will give us solutions to a specified level of accuracy rather than the approximate solutions that we are able to find graphically. However, there is no guarantee that fsolve will be able to find all the solutions. We will sometimes have to tell fsolve where to look. For example to tell Maple to look for the solution near x=7 we would use the command "fsolve(f(x)=g(x),x=6..8)" to tell Maple to look at values of x between 6 and 8. The ideal method would incorporate both approaches: use graphical analysis to determine the approximate solutions, and then use fsolve to get more precise values.

Part III. Symbolic vs. Numeric Evaluation.

Maple is a symbolic computer based algebra program. At all times Maple will attempt to return an exact value and it will do so symbolically. Maple will not return a decimal value unless you tell it to do so. For example, Maple knows the constant p . When you enter Pi at the command line, Maple returns the symbol p not a numeric approximation to p . If you want a numerical approximation, you must tell Maple to eval uate the expression to a f loating point number. This is done with the "evalf" command:

> Pi;

[Maple Math]

> evalf(Pi);

[Maple Math]

You can also specify the number of digits of precision that Maple will use. By default, Maple returns numeric answers with ten decimal places of accuracy. If greater precision is needed, we can tell Maple to use more precision by reassigning the value of the variable Digits.When you first start Maple, this variable has a value of ten. Suppose we need the value of p to fifty decimal places. We would do the following:

> Digits:=50;

[Maple Math]

> evalf(Pi);

[Maple Math]

Exercises:

1) Enter the following data into the computer with the name "lista". [Maple OLE 2.0 Object]

2) Prepare a scatter plot of the data you typed in as "lista".

3) Tell the computer that f(x)=x5+3x2-1. Then find f(99) and prepare a plot of the function f(x) for values of x between -10 and 10. Note that you must use a * symbol whenever you want to multiply.

4) Plot the function f(x)=4x   first from x=0 to x=1 and then from x=0 to 10 (turn in copies of both graphs).

5) Use a graph to estimate where x2 and 2x intersect, then use fsolve to find these points exactly.

6) To fifteen decimal places, what is the value of [Maple Math] ?

After you have completed the 6 problems in this lab, save your work to your disk by pulling down the file menu to "save as." It will ask you what drive you want to save the file to- your disk is in the "a" drive. After telling the computer where you want to save the file, you need to name your file. For future labs- its a good idea to save as you go along just in case your computer crashes.

After saving your work, please print out a copy of the exercises to be turned in. To print: pull the file menu down to the "print" command. The computer will display a screen telling you where it will print- either to the engineering building room 136 or room 138. Once you have checked where the computer will send its information, click "OK" to start the print job.