Chapter Two

Getting Started with Maple

2.1 SETTING UP YOUR WORK SPACE

An important part of scientific computing is being organized. Good organization provides you with more time for the important things like being original and creative in your work, as well as giving you more time to get your work done (or to play). This organizational concept is particularly true for scientific computing, where you may have to deal with many files or many versions of the same file. For students, good organization also keeps you on task.

An important step in organization is knowing where you have stored things. One of the best ways to get organized is to create files in directories and subdirectories (also called folders and subfolders). You need to be able to navigate through your directories, see your files, and tell what is in them by their names. In addition, you need to be able to create, copy, move, and remove files and directories. Finally, you should protect your files from accidental or unintentional intrusions.1 For whatever operating system you are using, try out and get familiar with the commands to:

•  list the names of all files and directories in your working directory or folder

•  list the names with details of all files and directories in your working directory or folder

•  display the name of the directory in which you are working

•  make (create) a directory

•  copy file1 to file2 and then delete file1

•  copy file1 to a different directory and then delete local file1

•  copy file1 to file2, leaving copy of file1

To get started:

•  Create a subdirectory Intro in your home directory.

•  Create subdirectories Week1, Week2, …, Week10 within directory Intro.

•  Place a copy of the Maple worksheet version of Appendix B, Maple Quick Reference, into the Intro directory. One way to do that is to Open the CD file with Maple and then SaveAs into your directory.

•  Change to the subdirectory Week1 and use it for this weeks’ work.

image

Figure 2.1 An image of Maple’s classic desktop environment.

2.2 MAPLE’S PROBLEM-SOLVING ENVIRONMENT

Maple is an example of what computer scientists call a problem-solving environment. View it as a complete computing system (a really big program) that does nearly everything you need for mathematical calculations and does it within an intuitive, graphical user interface. Maple and its cousins, like Mathematica, extend scientific computations from dealing with numbers to also manipulating algebraic symbols. Even though problem-solving environments are also used for numerical calculations, compiled languages are faster and more flexible. (Matlab, while also called a problem-solving environment by some, is predominantly a friendly interface for doing numerical calculations. It is often used for high-powered design, simulations, and data analysis.)

2.2.1 Look Around, Smell the Roses

Ideally, you are reading this as an electronic Maple worksheet (a file with the suffix .mws) within Maple. If not, we recommend that you do so or at least open up a Maple window to experiment with. To do so on a Unix/Linux operating system, type xmaple & at a Unix prompt. To do so on other systems, start it as you would any other program. You should get an interface like that in Figure 2.1.

Look around in the window and note how it has dropdown menus and buttons that make it look very much like a word processor or a text editor, with which you may already be familiar. Pull down the menus and take note of the types of functions they perform. Before you get in too deep, note that the File menu has both Close and Exit as options. Close will terminate the Maple window that you are currently working on, while Exit will terminate the entire Maple session.

One of the worst experiences in computing is losing a file containing all of your hard work. Beware, even though you may have assigned a name to a file, its contents do not get permanently stored until you issue the Save or Save As command. Although Maple will usually ask if you want to save a file before discarding it, it is a good idea for you to explicitly save your file in the desired location before exiting or closing. You save a file with the Save command (the Save command under the File pull-down menu). In fact, it is a good idea to save your file on a regular basis while working on it; then even if Maple crashes, you will not lose all your work.

The Save As command under the File pull-down menu lets you change the format of the file as well as the location where it is to be stored. (Make sure you save your files in a directory where you will find them again; the default directory may be in some godforsaken part of the computer.)

Exercise: Now do as you are told!

•  Save this worksheet to your home directory or one of your other places.

•  Now Close this window and see what happens.

•  Now Exit Maple, start it again, and then Return Here.    ♠

•  Welcome back! Observe that there is a valuable Help menu as the right-most menu. Before you try it out, be warned that the Help window may cover up the window in which you are reading this. You get back to this screen by going to the Window menu, which will show you all the windows that you have open. You select this one to place it on top.

•  Try out the Help facility and notice that you can search for commands, search on topics, or go on a tour.

•  Try selecting (with your mouse) a word in the preceding text, such as Exit. Then go to the Help menu and note there is automatically a menu item there for help on Exit. Go ahead and read what it says.

•  Go to the Help menu again and search for information on Help. Examine the changes in the windowing environment and the arrows on the Help dashboard pointing right and left. They are hyperlinks to other pages for you to try.

•  Select (highlight) the above paragraph by dragging your mouse over it (holding down the left mouse button). Now try out the buttons that center the selected text, that right- and left-justify it, and that make it bold (B), italic (I) or underlined (U). Likewise, you can select some text and change the values in the little white windows to the left of the B button and get all types of formatting options.

While we are talking about what Maple does with text, it is a good idea to experience Maple’s active section and subsection notation. Right below this paragraph is a boxed + indicating a collapsed section. Mouse clicking on the + changes it to a – and opens up the material in the section for viewing. Do it now and experience the power of Maple! Clicking on a – reverses the process; do it too to close up the sections.

2.2.2 Try It, You’ll Like It!

In a well-designed Maple worksheet, or book for that matter, the section and subsection titles should form an outline of the material covered. This outline assists the learning process, since looking at just the titles of the sections of a document helps map out your journey through the material. Try it with this document:

•  Go to the View menu and select Expand All Sections. Then select Collapse All Sections. Imagine how useful collapsing and expanding sections is for writing technical documents; you can first construct an outline by creating the section and subsection titles, and then fill in the material after the logic is clear.

•  Whoops! You have now uncovered some of the materials that we have tried to hide in collapsed sections. So, close this document without saving it, and open up the original again.

•  Return Here. During our ordering you about, you may as well open and close some windows. In fact, it is good to learn how to open and close windows properly before you run the risk of losing some valuable work. Try closing and then opening the window within Maple in which this text appears. With a Windows operating system, a window is closed by depressing the lower most button on the upper right side with the x in it; on a Unix/Linux system, a window is closed by pushing the lower-most button on the upper left side with a – in it, and then selecting the Close option. You will then have to go to the File menu and select Open, or select the name of this file, if Maple was nice enough to write its name there.

•  Try minimizing (iconizing) and then maximizing the window within Maple in which this text appears. With a Windows operating system, you minimize and maximize by depressing the lower-most button on the upper right side with an underscore _ in it; on a Unix/Linux system this is done by pushing the lower-most button on the upper right side with a center dot. in it. Then click on the maple-leaf icon to get the full window back.

•  Finally, find the button that makes the window in which you are reading this text smaller or larger—but does not close or minimize the window. On a Windows machine that button has a single box, or maybe two overlapping boxes in it; on a Unix machine it is a depressed or raised (shaded) single box.

•  Maple is placed in different modes when writing or when doing mathematics. Check that you are still in text [T] mode, go to the Insert menu, and insert a paragraph. This action just makes some space for you to enter the new paragraph, you must still do the writing. To do that, enter text in the space inserted for the new paragraph. Insert a section and enter several lines of nonsense text. Insert two subsections, entering several lines of text after each. Check if your little boxes are working right, and then try deleting your additions when they are in both expanded and collapsed forms.

•  Now try playing with the indent buttons (arrows, someplace above the B), as well as the three sizes of magnifying glasses or x’s (real cute) that let you progressively enlarge the screen as your eyes get tired (or old). Inspect the explanation of a button’s purpose that appears on the information bar at the bottom of your screen when you push that button and hold it down.

•  Before you start thinking that Maple is just a program for technical writing, take note of the three adjacent buttons on the task bar (on the top of the window) with Σ, T, and [> on them.

•  Press the T button. This action places you in text mode, in which you get these cute windows letting you control the text format, type, and size. Click your mouse into some existing text and start typing something.

•  Next push the Σ button and note that it tells you that this is for “inserting inert standard math into a text region.” (Inert math looks good but has no symbolic value.) This option is useful for writing reports (like this), since you can insert fancy symbols like image into your text. Usually inert math is black and active math is red when you enter it. However, some of the colors in this worksheet have been lost as it was transferred down from one generation of Maple to another. We could also have inserted math in executable or active mode as image. If you select either symbol by clicking on it, you can then use the button with the Maple leaf on it to toggle (switch back and forth) between executable and inert modes.

•  It sometimes may seem a little hard to get out of the executable math mode. If that happens to you, try pressing the T or the [> button to get back into one of the other modes. Just for fun, use your mouse to select the mathematical summation symbol above (just click on it). You will notice that the Maple command that is used to create this symbol appears in a little window at the top of the screen. Now click on the little x button that appears when the symbol is highlighted, and note how the command gets slipped into the text in place of the symbols. If you highlight the command and click again, the symbol is slipped back into the text. This series of commands acts like another toggle switch.

•  Seeing that you have messed up this worksheet over which we have labored so long, you do not want to save it, since that would replace our nice version with your messed-up one. (You may use the Save As option on the File menu to save your messed-up version as a different file.)

2.3 MAPLE’S COMMAND STRUCTURE

At last we will do some mathematics with Maple.

•  Pressing the [> button places you in the execute mode that permits manipulation of symbols and expressions. The greater-than symbol > is Maple’s way of prompting you to enter a command to the right of it (in fact, it is called a “prompt” for just this reason). When you enter commands after the [> prompt, Maple gets to work for you. If you enter commands while Maple is in the text mode, then Maple just copies them onto the worksheet and sits there awaiting your next entry.

•  Place Maple into execute mode, tell it to add 3 + 82, and then hit the Enter/Return key. Observe that your command to Maple shows up in red and is in a fixed-width font like a typewriter or a teletype. The teletype font is meant either to evoke the aura of the computing days of the past or to indicate that this is your command to the computer. Check next that Maple speaks back to you in blue and black. If you did as told, Maple has probably responded with a blue streak:

  Warning, premature end of input

  This warning is Maple’s way of saying that it does not think your command is over yet, even though you appear to think so. To end your command properly you have place a semicolon ; at the end of the line before hitting the Enter key (on some computer systems you may have to hit the Return key).

•  So, go back into execute mode [>, insert two prompts into the text, enter 3+82; after the first prompt, and then hit Enter. This command should give 85 as an answer and leave you at the next prompt [>.

•  Now use the arrow keys to go back up in this worksheet and fix your previous command by placing the missing ; at its end (after the 82). Then pressing Enter should fix things up. In general, when you make a mistake you can go back to the command you have already entered, correct it, and then hit Enter/Return any place in the command to execute the command again. This correction is a lot better than trying to enter the entire command again, especially when the commands get complicated and you are annoyed with the computer and the slow pace of learning. (It is an often-experienced but not fully tested fact that computers seem to know when you are annoyed with them, and then react by giving you an even harder time.)

•  To get the most out of this tutorial you should personally key in the Maple commands rather than cut and paste them to a Maple prompt. In order to force this point, we make some commands inert. A good way to enter commands is to go to the File menu and start a New window within Maple (you may have many windows open simultaneously).

•  If you go back to the first [> prompt in the Maple worksheet version of this text and hit Enter, you will note how after executing your command, Maple automatically skips down through the text and output to the next [> prompt and waits there for your next command. In this case, Maple’s response means that unless you get into the habit of inserting some extra prompts in your document, you may end up skipping over some valuable material.) So find your way back up to this point in the worksheet and note the action of the Tab key. It jumps you through the worksheet with stops at each prompt or executable expression.

•  In the next section you will enter a new calculation on your worksheet directly after the (blue) result of a previous calculation. To do that, place your cursor to the left of the previous result (possibly 85), and press the execute [> button, causing a new execution group to start at that location.

2.3.1 Maple as a Pocket Calculator

Maple does everything a pocket calculator does and much more. It understands the usual arithmetic operators, + and – for addition and subtraction, uses * and / for multiplication and division, and understands either ** or for exponentiation (raising to a power). As an example, 3 × 45 – 76 would be entered as 3*45-7 ˆ 6, where the spaces do not matter. Go ahead and try it by placing your cursor anywhere after the prompt below and hitting Enter.

image

Look at how Maple has jumped to the next prompt. If we had not placed an extra [> there, you would have had to look for the cursor and bring it back to here.

2.3.2 Rules of Precedence

When performing calculations like those above, it is important for Maple to know the order in which you want the various operations performed. The order of executions (also followed by most pocket calculators) is

image

There may still be ambiguity, depending upon the way in which you apply this rule. As a case in point, let us say we want to add 4 to 2 and then multiply the sum by 3. Have Maple try this by evaluating the (ambiguous) expression 4 + 2 * 3.

•  If you got the answer 10, then you did not do what we wanted. Clearly, this calculation is a case where the order of operations matters. Try (4 + 2) * 3, where the parenthesis makes our intentions clearer.

•  Next try 400/10/2 and explain your result. Because computers tend to do division from left to right (left associative), Maple knows what it is doing, but the result may not be what you want.

•  Now see if 400/10/2 is the same as (400/10)/2 or 400/(10/2). In the worksheet we give you only one prompt for this as a way of encouraging you to try entering the three commands on a single line with a semicolon ; after each command, but only one Return at the end of the line.

•  Remember, if there is a chance that the results may be ambiguous or unclear, use parentheses to force the operations you want and to ensure clarity. For instance, enter 4 ˆ 5ˆ6.

image

Maple tells you something is wrong. At times when Maple cannot figure out what you have told it to do, it may respond by just repeating your command back to you (a polite way of suggesting that you get it right next time).

2.4 SUMS AND SUMS

Many problems in science and mathematics require you to evaluate sums. At times the sums are over a finite number of terms, and at other times the number of terms is infinite. With a little cleverness you can write a sum as a single expression. As an instance, here is an infinite sum

image

The summation index i starts from 0 and runs all the way to infinity. We show two related ways to enter sums into Maple. The first is

image

In spite of this output being pretty and being a great way to check that you have entered the sum correctly, it is inert (cannot be used to do the math). The active form for this sum, as well as a number of other functions in Maple, is obtained by writing the function without the capital letter, in this case as sum(. . .). Try converting the passive sum to an active sum:

>           # Paste and edit passive form here

If life is fair, you should have obtained cos x as the value that Maple actually evaluates for the sum. This means that Maple has recognized this infinite sum as the power-series expansion for cos x. Actually, you can have the best of both worlds; use the command Sum to have Maple show you what it thinks you want (useful for debugging your typing), and then enter value(%) to have Maple perform the calculation:

image

Take a close look at the Sum() command we have used here. Like all Maple commands, it has a format that should be followed precisely (although inserting spaces causes no harm). To begin with, note that after the name of the command there is a pair of parentheses. The parentheses contain the arguments to the command. In this case, there are two arguments separated by a comma. The first argument or field contains the expression to be summed, while the second field contains the range of values to be covered by the summation index.

Descriptions of ranges in Maple are of the form i = a..b or i = a .. b, where a and b are the lower and upper limits of the range (b = for our example). If you deviate from this format, Maple may tell you that you did something wrong, or Maple may assume that you know what you are doing (Maple is good at math, not at judging character) and make a reasonable attempt to follow your command. To illustrate, try these:

image

In the first case you should get an error message, while in the second case Maple evaluated the sum treating infty as if were just another algebraic symbol.

2.4.1 Strings and Quotes

In those cases when there is not an inert form of a command, you can still get Maple to produce output that contains your command and Maple’s response on the same line. You accomplish this task with the judicious use of quotes. However, since Maple contains three types of quotes, “double quotes,” ’left quotes,’ and ’right quotes,’ this whole quoting business gets to be rather confusing at times (Landau’s second rule):

Maple’s quote types.

Example

Name

Function

“a string”

double quotes, quotation marks

creates a string

‘John Dull‘

left quotes, accents grave, back quotes

delimits names

’x^3 ‘

right quotes, apostrophes

suppresses evaluation

We start with double quotes. Anything placed inside of double quotes becomes a string. A string is just a sequence of characters that is treated literally with no inherent meaning or value. As an example, the string “this is now a string” is just letters and spaces to Maple. However, variables can be assigned to strings, as if the strings were their values, and these variables can then be manipulated. (We shall see in our study of Java input and output, that strings are parsed to extract their meaning.) Here are some examples:

image

image

In this case we see that the double quotes showed the command as entered, with the quotes themselves visible in Maple’s response. The left (back) quotes produced a similar output, but with the quotes not visible and with a font change. In contrast, the right quotes may have delayed some execution, but not enough for this simple a calculation to stop Maple from returning just a number.

We will often use these left and right quotes to produce nice output and to assist in the learning process. Likewise, you may want to use them to produce nice worksheets. In the next examples we see more clearly that the left quotes just show us what command we have entered, while the right quotes have Maple set the command in proper mathematical notation, but not evaluate the expression:

image

Now we enter some strings and manipulate them:

image

An important use of the backquote is to enclose names containing spaces or special characters that might otherwise give Maple trouble. For example, if the name you give to a variable contains a space, then Maple (and Unix) will assume that it is two names. Yet if you place the two names within back quotes, then the two words will be treated as a single grouping:

image

Scrutinize how the item within left quotes is not the same as a string (which is just a literal recall of the characters); the name in back quotes is the true name of some item in Maple:

image

In summary, use double quotes “…” for strings, left quotes ‘…‘ for a name that contains spaces or special characters, and right quotes ’...’ to delay execution of a command.

2.5 EXECUTION GROUPS

In the electronic version of this book, we usually want you to observe the effect of a single, or each group of, commands one at a time. For this reason we often place the symbol [> in our Maple worksheets to stop execution. As a case in point,

image

[>

Monitor how Maple jumps through all these commands in a flash and then stops at the blank prompt. Now remove these lines of output (either by selecting them and hitting the Delete key, or by using the commands in the Edit submenu), place your cursor at the last of the three commands (the one dealing with sqrt(10)), and hit Enter again. What is happening here is easy to understand. The Maple prompt (the symbol that indicates Maple is ready to have a command entered) is the greater-than sign >. The long and short square brackets on the left indicate execution groups. The rule is that

Maple executes all commands within an execution group and then jumps to the next execution group to resume execution.

So in our case, we see that Maple stopped at the [> symbol because it is the next execution group, not because it was a blank prompt! To test this rule, select and then delete the blank prompt above this paragraph, and execute the preceding execution group. You should notice that Maple now jumps to the execution group below this paragraph.

An execution group may contain things like text and graphics, in addition to commands, and may get to be quite long. As such, they are a convenient way to organize your worksheets. In this book we will keep our execution groups small in order to encourage you to study the consequence of each command. We suggest that you also keep your execution groups short as a way of reviewing what your worksheet is doing and of checking that it is working properly.

When you insert an execution group, Maple also inserts a command prompt from which you execute commands. To insert an execution group:

•  Go to the Insert menu.

•  Choose Execution Group.

•  Choose Before or After Cursor.

To add more command prompts to an existing execution group,

•  Place the cursor to the left of an existing >.

•  Hit the Enter key.

•  Check that the new prompt appears above the original >.

On occasion you end up with a bunch of execution groups that would be better off joined together. To join two or more execution groups:

•  Place the cursor in the first of the two execution groups to be joined together.

•  From the Edit menu, choose Split or Join, and then Join Execution Groups.

•  Press the Enter key.

Alternatively, each computer system has some function keys that let you join and split execution groups rather easily. (They are F3 and F4 on the systems we have tried.) The joining of execution groups works from top to bottom, the splitting from bottom to top. Each time you enter the command, another group gets added or split. To illustrate, the following (whose mathematics we will come to in due course) is a single execution group, with one prompt before and one after the commands:

image

Try splitting this group at the beginning of the Diff line to produce two execution groups. Then try joining the split groups into one execution group. Execute the result to make sure both commands are done in a single execution.

2.6 KEY WORDS AND CONCEPTS

active mathematical expression

arithmetic expression

command

execution group

hidden section

inert

mathematical expression

on-line help

prompt

precedence rules

strings

1.  Explain the meaning of these key words.

2.  Mathematics is often called the universal language of science. Evaluate this remark in the context of what Maple does.

3.  What is the difference between a Maple command and a Maple response?

4.  How does Maple differ from a pocket calculator?

5.  How does the computer know the difference between a string and the name of a variable?

6.  If computers at their heart understand only numbers, how does Maple understand algebraic symbols?

2.7 SUPPLEMENTARY EXERCISES

1.  Use the text mode of Maple to write a worksheet containing:

a.  Your name

b.  Your educational level

c.  Your computer experience

d.  What you would like to get out of this course (or book)
Convert your name into a bold font, convert your educational background into italics, and underline your experience. It is a good habit to save your worksheet often as you are working on it, and especially before trying to print it out. Sooner or later it is likely that Maple will freeze up or quit on you and lose track of the active worksheet. That being the case, you will only have to make up the work since your last save.

2.  Save your worksheet as a file in the directory Intro and the subdirectory Week1. Do not close the worksheet yet.

3.  Print out this first worksheet and hand it in. To do that, you may have to look at the page that comes up when you issue the print command and pick the printer to which you want the output sent.

4.  Use the sum command to find a simple expression for the sum of the first n integers, 1 + 2 + …n. You might want to experiment with the commands simplify(%) and factor(%) to get a compact expression.

5.  What is the ratio of (n+1)! to n!? How about (n+50)! to n!? What happens when you try to calculate the ratio of (n + m)! to n!? Use simplify(%) to get a better idea of the result. Do you obtain what you expect to? Explain.

6.  Make three different execution groups, with the last two ending in a blank line of execution (that is, as >).

a.  Have each group contain four lines, and have each line raise 2 to a power equal to the sum of the line number plus execution group number.

b.  Now enlarge each execution group so it contains an additional line for input, namely, an extra >.

c.  Add comments on your choice to one of the execution groups.

7.  Evaluate

a.  sin(pi), sin(PI), and sin(Pi) and explain,

b.  the natural logarithm of e, the base for natural logarithms,

c.  the natural logarithm of 10,

d.  the logarithm to the base 10 of 10.

8.  Explore two ways of accessing Maple’s on-line help.

a.  Use Maple to select the word help from the above line and then go to the Help menu on the Maple dashboard (in the upper right), and get help on help.

b.  Insert an execution group on this worksheet and enter the ?help command.

9.  Verify that the following infinite series equals π/4:

image

10.  (Optional) Although you may not believe it, the following infinite series equals π/4 for all 0 < x < π:

image

  See if you can manipulate Maple to give this result. Even getting Maple to indicate that the sum is independent of x is a step in the right direction.

11.  Use the precedence and arithmetic rules of Maple to predict the values of each of the following expressions:

a.  2 ×3 + 4/2

b.  5 – 6+72

c.  1 – 23/4

12.  Use the precedence and arithmetic rules of Maple to predict the values of each of the following expressions:

a.  (4/2)3 – 78 + 7**8

b.  10/14

c.  10./14

d.  8/(4/2)

e.  8/4/2

f.  62 + 5 – 7

g.  8 + 24/2

13.  For the following inputs, what would Maple produce as output:

a.  sum ( (-1)ˆi / (2 * i)!, i = 1 .. 2)

b.  Sum ( (-1)ˆi / (2 * i)!, i = 1 .. 2)

c.  sum ( (+x)ˆi / (2*i)!, i = 1 .. 2)

1How to do these things under Unix is explained in [L&F 93] or the Web tutorial [UnixWeb].

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset