> restart;
>
Introduction to Maple
Maple is a powerful computer algebra system. It can solve many calculus problems at a click of a button. In order to make full use of Maple's power you have to learn the way of telling Maple what you want it to do; that is, you have to learn the correct Maple syntax . You also have to learn how to handle Maple worksheets . Below is a short introduction to using Maple and its basic commands. We shall introduce more advanced commands in subsequent worksheets. The book Getting Started with Maple that came with your course textbook is your basic reference, if you need more information.
Maple Worksheets
A worksheet, like this one, consists of text and Maple command lines. You toggle between the text mode and the command line mode by pressing the buttons marked "
T
" for text and "
[>
" for the command line. The buttons are located on the toolbar above. (The third button "
" allows you to enter mathematical equations while in the text mode. You will not have to use this button much.) You enter text in the text mode. You enter Maple commands in the command mode following the prompt "
>
". Commands that you type usually appear in red. Each command has to end with a semicolon. (Ocassionally, if you don't want Maple to print out the output you end your command with a colon.) After you are finished typing a command press "Enter" and Maple returns an output. Outputs are usually displayed in blue. You save worksheets and open new worksheets by clicking on the appropriate icons on the toolbar, as in any other application.
We shall switch now to a command line mode and ask Maple to perform some simple calculations. Let's tell Maple to calculate
. We type our command at the command prompt, press "Enter" and Maple returns an answer.
> 2*(359+23)-(5+21)/(2+11)+25^9/32456789999;
>
As you see, the rules of entering arithmetical operations are similar to those on your calculator. Multiplication is always denoted by " * ", division by " / ", exponentiation by " ^ ", addition and subtraction in the obvious way. The proper use of paretheses is, of course, crucial to correct syntax. As in the above example, whenever possible Maple will return an exact answer. If you want a decimal form, or in other words, a floating point approximation of your answer, you have to use the command " evalf ". (The"f"at the end of the command stands for the "floating point", "eval" for "evaluate".)
> evalf(%);
>
The symbol " % " in Release 5 of Maple denotes the last executed output; that is the output of the command on which you clicked last. (It was " instead of % in earlier releases.) The symbol " % " easily leads to confusion and you will be better off using it always on the same command line as the command to which it refers. You can enter several commands on one line, end each with a semicolon, and then press "Enter" to execute all of them. For example
> (2*7+23)/(17-2); evalf(%);
>
Maple gave the exact version of the answer, followed by its floating point approximation.
This worksheet, as well as the subsequent ones, are fully interactive . You can change each of the commands or parts of them, press "Enter" and see the results. Try changing numbers and the location of parentheses in the example above. After you click "Enter" on a command line the cursor jumps to the next command line.
>
Press "Enter" on the lines below. Do you expect to obtain the same output for both of them?
> 3*5+2/7; evalf(%);
> (3*5+2)/7; evalf(%);
>
The portions of a worksheet consisting of text or a series of command lines are called execution groups . To open a new execution group after what you have just typed simply press " [> " on the toolbar. To insert a new execution group before a portion of already typed text, if you ever need it, place the cursor at the beginning of the text, go the "Insert" menu click on "Execution Group", then "Before Cursor".
Note: If you want to interact successfully with a worksheet, you have to re-execute , in sequence, all the commands in it. That is, you have to click "Enter" on all commands lines, beginning with the " restart " command, which clears Maple's internal memory of all prior assignments and definitions, forward. Even if command outputs were saved before, and they appear already on screen, you still have to re-execute commands. It may not matter with simple commands like the ones that you have seen above, but it does matter if a command defines or labels a function or any other object. If you don't re-execute such commands you may see strange error messages as Maple will not recognize functions, expressions and other objects that have been defined in the worksheet you opened.
>
Defining Functions
As you probably know calculus is a study of functions. In this section we show the proper syntax for defining and working with functions in Maple. The best way of learning syntax and illustrating what Maple can do is by examples. Hence we start from the following problem.
Example 1. A rumor is spreading among a group of 200 people in an isolated region. The number of people, N( t ), who have heard the rumor by time t , measured in hours since the rumor started to spread, can be approximated by the following function
.
How many people have heard the rumor after 20 hours? After 30 hours? How long will it take for half of the population to have heard the rumor? When will practically everyone hear the rumor? When is the rumor spreading fastest?
Maple can answer all these questions for us. The first step is defining the function N( t ) in Maple. A function is defined in the following way
> N:=t->1.00503/(.00503+.84^t);
>
Note the proper syntax for entering functions! " N " is the name of the function, " := " means in Maple "define". As you know, a function is a rule which to each input, say t, prescribes the output given by the formula for the function. The proper Maple syntax, using the arrow " -> ", reflects this interpretation of a function. You type the arrow using the "minus" and the "greater" keys. Like every command in Maple, our definition ends with a semicolon.
The number of people who have heard the rumor after 20 hours is given by N(20). Once the function N( t ) is defined, we ask Maple to calculate N(20) using the simple syntax:
> N(20);
About 28 people have heard the rumor after 20 hours. Let's calculate a few more values of N( t ).
> N(0);N(30);N(35);N(40);N(50);N(60);N(70);
>
As we see, initially, at t = 0, only one person knows the rumor, then the number increases. After about 70 hours practically everybody has heard the rumor.
Note: If you enter
> M:=1.0053/(.00503+.84^t);
>
you have not defined a function of t but an expression M in terms of t . Maple can process functions as well as expressions but the syntax is often different.
Plotting
The best way to see how a given function behaves is by ploting it. Let's plot the function N( t ) of the above example. Clearly, the usefulness of our plot depends on the proper choice of the range for our graph. The numbers above give us a pretty good idea that within about 70 hours practically everybody has heard the rumor. Hence, we shall graph the function N( t ) for t between 0 and, say 75. The proper command for graphing a function is
> plot(N(t),t=0..75);
>
The graph shows clearly how the number of people who have heard the rumor increases, first slowly as the graph climbs slowly, then faster, until it eventually levels off at about 200 when everyone knows the rumor. The rumor seems to be spreading fastest around t = 30 as the curve seems steepest there. We shall be able to answer the question exactly later on in the course when we already know derivatives.
We shall make extensive use of Maple's plotting facility. You can plot functions without necessarily giving them names and defining them as in the example above. You simply type the " plot " command and enter a formula for a function and the range you want it plotted in. Before clicking "Enter" on the lines below, try to predict what you are going to see.
> plot(x^2,x=-2..2);
> plot(2*x^3,x=-1..3);
> plot(3*t+1,t=0..5);
>
Solving Equations
To answer the remaining question of Example 1 "When has half of the population heard the rumor?" we can try to estimate the time from the graph. It seems that somewhere between t =30 and t =35, 100 people have heard the rumor. To find that time precisely, we need to solve for t the equation N( t ) = 100 . Maple can solve equations and the syntax is
> solve(N(t)=100,t);
>
After approximately 30.37 hours, 100 people have heard the rumor.
As you know, solving equations is no easy matter. Maple's equation solver knows all standard methods for solving equations, but for many equations there are no general methods for solving them. In that case we shall resort to finding approximate solutions by solving equations numerically, which is evoked by the " fsolve " command. We shall see examples of that in subsequent worksheets. For reasonably simple equations Maple can find exact solutions even if a given equation contains letter constants, that is, parameters . For example
> solve(x^2+a*x+b=0,x);
>
Using Maple Help
Maple has an extensive on-line help and it may be a good idea to learn how to use it. For example, you want to factor a polynomial, say
.
To find a Maple command to do this, select Topic Search... from the Help menu. Then type "factor" because that's what you want to do. Among the choices that come up, you see "Factor" and "factor". Both look promising. Say you want to try "Factor" first. Click on it to select it and then double click on it to open the corresponding Help menu. A long page comes up. Scroll down to examples. The examples look nothing like you want. Try "factor" instead. That's it! The first example on the page that comes up looks almost exactly as what you want. It is an example of how to factor the polynomial
. You can remember the syntax and use it to solve your example, or, if the syntax is complicated, you can copy an example from Help menu into your worksheet as follows. Highlight the command line that you want to copy. Click on Copy under the Edit menu and close the Help screen. Open a new execution group in your worksheet by clicking on the "
[>
" button. Move the cursor to the new "
>
" prompt and then use Paste. Below we have done just that.
> factor(6*x^2+18*x-24);
Now we can simply follow the syntax to factor our polynomial.
> factor(x^3-3*x-2);
Done. You could have arrived at the right help menu by typing "polynomial" instead of "factor", and navigating your way through a series of menus which appear on the top of the screen. Try this as an excercise.
>
Homework Problems
This, as well as all subsequent Maple worksheets, contains homework problems. To solve your homework problems open a new Maple worksheet by clicking on the blank page icon on the toolbar. Enter your name, the title of the worksheet to which the homework corresponds, numbers of consecutive problems using the text mode " T ". Usually, all you need to solve homework problems is to read each worksheet and carefully follow the syntax in it. Do not skip commas, semicolons, parentheses, stars denoting multiplication etc.. Your syntax has to be precise in order to work. After using Maple to plot graphs, perform calculations etc., whenever appropriate, as in Problem 1 below, explain your answers in practical terms. Your explanations, in complete sentences, should be typed using Maple's text mode .
Problem 1. The population P( t ), in thousands, of a town t years after January 1, 1990 is given by the function
.
(a) Define the function P( t ) in Maple.
(b) What was the population on January 1, 1996? On January 1, 1998?
(c) Plot the graph of the population from January 1, 1990 until January 1, 2010.
(d) Assuming that the present trend continues, when will the population reach 40 thousand?
Problem 2. Find the exact and the decimal value for
.
Problem 3. Solve the equation
.
>
Note. When creating your homework worksheets, you may choose to start them with the " restart " command or you may not. Both ways have advantages and disadvantages. The " restart " command clears Maple's memory from all prior definitions, assignments and starts Maple from scratch. This often helps to avoid confusion. On the other hand, if in your homework problems you are asked to do more work with functions that were already defined in the original worksheet and you use the "restart " command, you will have to redefine the functions as the command erased them from Maple's memory. Follow your own judgement when using the " restart " command. For the homework in this worksheet, using or not using the command will make no difference.
>
To understand how the " restart " command works, execute the command lines below, in sequence, at see what happens.
> restart;
>
Maple has been started from scratch.
> f(2);
>
Maple doesn't know what f(2) is as no function f(x) has been defined.
> f:=x->x^2;
>
The function f ,
has been defined.
> f(2);
>
Maple knows the function f.
> restart;
> f(2);
>
Again, Maple doesn't know f.
>
MTH 141 Maple Worksheets written by B. Kaskosz and L. Pakula, Copyright 1998.
Last modified August 1999.
>