Calculus B - Lab 1 

TA: Patrick C. Rowe 

> restart;
 

Setting up Maple 

Worksheets vs. Documents 

 

Maple 11 has two modes - document mode and worksheet mode. In this class, most of what we do will be in worksheet mode. To open a new worksheet, as opposed to a document, go the the File menu and choose New->Worksheet. 

 

 

2D Math vs. Maple Notation 

 

Maple also has two basic modes to enter mathematical commands. The default mode on most machines is 2-D Math. 2-D Math is a text style designed for writing reports and presentation quality mathematics. Once a person has learned Maple and understands the command structure, it is a great tool. However, while learning Maple it has the disadvantage of obscuring keystrokes. To avoid this, we use Maple notation which is the more traditional format. This displays every keystroke and make its easier to find errors. Look at the following two examples: 

 

2D Math: 

Typesetting:-mrow(Typesetting:-mn( 

 

Maple Notation: 

> 2*x^2;
 

In both cases, the same keystrokes were entered (with the exception of the semi-colon). You can see that in 2D Math, the keystrokes were obscured and if not known to the reader, would not be discernible. For this reason, all the labs will be written in Maple notation and it is important that any work you turn in be written in Maple notation. 

 

To do this, you need to change the default for the Maple input mode. Go to the Tools menu and select Options. A dialog box will open. Select the Display tab and change the Input Display drop down menu to Maple Notation. 

 

The 'restart' command 

 

The restart command is used to clear all variables and output from the memory of the current worksheet. It should be entered at the beginning of each worksheet. This will allow you to use the !!! button on the toolbar which executes all the commands on the worksheet. If you don't enter the restart command data or values from previous problems could be incorrectly used and you could get the wrong answer. 

 

It should also be entered between each problem you solve. This way you can make sure that each problem uses only its own data. 

 

For an example look back at the beginning of this document. 

 

Section Summary: 

 

 

 

Basic Commands + , - , * , / , ^ , ( ) , := 

The basic math commands work as expected. Simply enter the expression followed by a semi-colon and Maple will output the answer. 

 

Addition and Subtraction 

> 2 + 3;
 

> 4 - 5;
 

 

Multiplication and Division 

> 2 * 3;
 

> 2 / 3;
 

> 6 / 3;
 

 

Exponentiation 

> 3^2;
 

 

The normal order of operations are followed. Exponentiation precedes multiplication and division which precedes addition and subtraction. Operations of equal precedence are read left to right. 

> 2 + 3^2 * 2;
 

> 6 / 3 ^ 2;
 

> 6 / 3 + 4;
 

 

To make sure that the order you desire the operations to be carried out is followed, parentheses should be liberally used. 

> (2 + 3)^2 * 2;
 

> (6 / 3) ^ 2;
 

> 6 /(3 + 4);
 

Assignment Operator 

 

Of course, to perform operations of this level, we don't need a computer. We want to perform operations of a much greater complexity and with variable inputs. The first step in this direction is the assignment operator which is :=. 

 

We use the assignement operator to store values in variables. We can store numerical values, but also, as we'll see later, functions, expressions, and anything we want. 

 

The operator works from right to left. It stores the value on the right in the name on the left. See the examples below. 

> x := 5;
 

> x + 2;
 

> y := 10;
 

> x + y;
 

To unassign a variable, assign it to its own name as follows. 

> x := 'x';
 

> x + y;
 

Note that Maple calculates the expression as far as it is able and then produces output. 

Functions and Expressions 

> restart;
 

Mathematical statements can be entered as both functions and expressions in Maple. However, Maple treats the two types differently. 

 

To enter a statement as an expression, simply assign it to a variable with the assignment operator. 

> f:=4*x^2 - x;
 

To enter a function, we need to use a different method. A function is an operator and takes a value to a series of commands. The input notation expresses this. 

> g:=x->4*x^2 - x;
 

Lets try to find the value of this mathematical statement when x = 1 by using both the variables f and g.. 

 

If we use typical mathematical notation, we get some unusual results. 

> f(1);g(1);
 

We see that one way produced the desired result, but the other didn't. This is one difference between functions and expressions.  

 

To evaluate an expression at a specific value, we use the subs command. 

 

> subs(x=1,f);
 

What if we assign the value 1 to x permanently by using the assignment operator? What will the values of f and g be then? 

> x:=1;
 

> f;
 

> g;
 

> g(x);
 

The assignment to x changed the value of f. For g, the value was unaffected unless x was 'plugged in'. This reveals a fundamental difference between functions and expressions in Maple. Expressions are associated with the variable used in their construction. Functions are not. Functions are a rule to perform on values plugged in to them. This difference is reflected time and again in the way that functions and expressions are used in different commands so you should always be aware which the variable in question represents. 

>
 

The Basic 'plot' Command and the 'display' Command 

> restart;
 

Plot Command 

 

The plot command is the basic graphing command in Maple. Learning how to use it well and its basic syntax will enable you to easily learn the other commands. 

 

First, we need a function or an expression to graph. 

> f:=x^2;
 

To graph the expression, simply enter the plot command and the variable range to graph over. 

> plot(f,x=-2..2);
 

Notice that it is necessary to specify the variable which is being ranged over. This is because the expression is associated with the variable. For functions, we only need to specify the range. 

> g:=x->(x-1)^2;
 

> plot(g,-2..2);
 

Notice that the functions plotted in red. But the color can be changed, also the linestyle. In fact, there are many options which can be set. For now, we'll only be concerned with these two. For more possibilities see the 'plot\options' page in the Help. 

 

To change the color, simply add the statement color=[selection]. The color choices are aquamarine, black,  blue, brown, coral, cyan, gold, green, gray, grey, khaki, magenta, maroon, orange, navy, pink, plum, red, sienna, tan, turquoise, violet, wheat, white and yellow. Colors can also be defined by numerical values. See the plot\color page in the help for more information. 

 

To change the linestyle add the statement linestyle=[selection]. The choices are SOLID, DOT, DASH, or DASHDOT, entered in all caps. 

> plot(g,-2..2,color=blue,linestyle=DOT);
 

Display Command 

 

These are very useful when used in conjunction with the display command which lets you show more than one plot on the same set of axes. 

 

Although the plot command is part of the basic Maple command set, the rest of the commands associated with plotting must be loaded before being used. This is done by using the with command to load the plots package. See the example which follows. 

 

> with(plots);
 

Now, the display command can be used. 

Although automatically displayed as a graph, the plot command actually outputs a large amount of data which is called a 'plot data structure'. This data can be stored in a variable instead of automatically graphed and then displayed when desired. All the variables entered into the display command are shown on the same axes, making comparisons very easy. 

> p1:=plot(g,-2..3, color = blue);
 

> p2:=plot(f,x=-2..2);
 

> display(p1,p2);
 

 

Exercises 

1. Open a new worksheet. (Remember to make restart your first command.) 

 

2. Define 2 variables to have the value sin(x). One should be a function and the other an expression. 

 

3. Store the value π/17 in a variable. (π is entered by typing Pi. The capital 'P' is necessary to indicate the number pi. Using the lowercase 'p' means the Greek letter.) 

 

4. Evaluate sin(π/17) using both the function and the expression. 

 

5. Define another variable to have the value (1/2)*x. 

 

6. Plot sin(x) and (1/2)*x on the same axes. Make sure the graphs are different colors. 

 

7. How many times do the curves intersect? 

>