Chapter1.mws

Chapter 1: Getting started

Click on each subsection below, read and execute the Maple commands, and do the problems at the end of each one. There is a hyperlink at the top of each subsection called Debugging that will take you to the section at the end of the worksheet that discusses what errors mean and how to fix them.

Execution groups and paragraphs

Debugging

The first thing you will notice when you turn Maple on is the square bracket on the far left and the > sign just inside it. These two symbols are the most basic parts of Maple's graphical user interface and they will drive you crazy if you don't learn to handle them well right from the start. The window space marked off by the the square bracket is called an execution group and everything happens inside these groups. Here's what you have to know: everything before the > sign is text, or typeset mathematics, and the red stuff that comes after is Maple code that will execute to solve your problems. Maple results print in blue, like this:

Sine function, sin(Pi/4)

> sin(Pi/4);

1/2*sqrt(2)

>

The purpose of the text portion is to document what you are doing. Please document your code. I will be glad you did, the grader will be glad you did, and six months from now when you remember that you once solved a problem like the one you just got assigned and you go looking for it, you will be glad you did.

Within execution groups are subunits called paragraphs . A paragraph might be a section of text, a Maple command, a Maple result, or maybe stuff neither one of us knows about yet. It's a little complicated. The easiest way to see what paragraphs are is to click on the little paragraph icon (backwards "p"-looking thing on the tool bar). This will print the special characters in the worksheet and will show you where the paragraphs are. Do it now and leave it on for a while until you get a feel for what paragraphs are.

Now hang in there, you're about to actually do something. There are two execution groups just below this section of text. Put text that says Kindergarten stuff before the > sign in the first one (move the cursor just to the left of the > sign by using the arrow keys), hit Enter; then put 1+1 after the > sign and hit Enter again

>

You should now be looking at a mess inside the execution group; 1+1 didn't work and you got an error.

First things first, and this is important: the error occurred because Maple requires every executable statement to end with a semicolon or a colon . If you end with ; then the line will execute and Maple will tell you what it did. If you end with : then the line will execute, but Maple will not display the result. This is very useful if you know the result is OK but it's such a big mess that you don't want to see it.

Anyway, to get 1+1 to work you need to type 1+1; to get the usual answer. But first you had better clean up the mess. The error line is a paragraph. If you try to delete it with BkSp or Del, nothing will happen because these are lines that Maple generated. To kill it you need the Delete Paragraph command in the Edit menu on the toolbar, or just type Ctrl-Del. You will be using Ctrl-Del a lot to get rid of unwanted junk in execution groups. Be careful, though; it will kill the whole paragraph . So unless you are sure of what is in the paragraph in question, click on the paragraph symbol and see how the paragraphs are arranged. Note that you can also use the mouse to highlight text to be deleted by clicking and holding at the beginning of the offensive material and dragging the cursor to highlight everything that has to go. Then just press Del. Ok, so use Ctrl-Del, or mouse highlighting and Del to get rid of the error message. Then use the mouse to move the cursor to the end of 1+1 , tack on the semicolon, hit Enter, and you will have used Maple to find out that 1+1=2. (Note that the answer comes out in blue in the center of the page). And all of the cut, paste, copy, etc., stuff you are used to is available in Maple under the Edit icon on the toolbar. One final note. You probably noticed the extra execution group after 1+1;. This extra one is there as a trap. Whenever Maple performs the commands in one execution group, it skips down to the next one. If the next one is way far down in some text (like here in this section) your desired result will be clear off the screen and you will need to move back up there to see it. You will see lots of traps like this in this document, but in Maple code that is not heavily documented, they aren't necessary.

Maple will allow you to do more than one calculation inside an execution group. You can do this in two ways: (i) with several commands on a single line separated by semicolons, or (ii) several commands stacked vertically, each with its own >. To get extra >'s, just move the cursor to the left of the first > and hit Enter. Examples that you can execute are displayed below; try them out. Oh, and notice how the # symbol can be used to add brief comment lines in red right on the command line. The rule is that anything after # is a comment

> 1+1;2+2;3+3; # three additions in a row

2

4

6

> 1+1;

> 2+2;

> 3+3;

2

4

6

>

OK, hopefully this is enough to get you around on the window. There are a lot of things that won't be mentioned here, but they are all described in online help and you can find most of them on the toolbar. This might be a good time to take a tour of the toolbar to see what's up there. To begin, click on Help and enable Balloon Help; then move the cursor across each icon to see what each one is about. And for a more thorough introduction to the way the window is managed, click on Help and try the New Users Tour. After you click on the New Users Tour go to the bottom of the introduction page and click on the blue hyperlink called Click here to begin the New Users's Tour , then select item (2), The Worksheet Environment . Oh, and when you want to close a Help screen, use Ctrl-F4 or the X at the upper right-hand corner of the window (in Windows).

Problem 1.1

Make an execution group and document it before the > sign with the phrase:

Add the integers from 1 to 10.

Then build a Maple command line to get the answer to 1+2+3+...+10.

------------------------------------------------------------------------------------

Go to top of section

Quick guide to managing the worksheet

Debugging

This is just a collection of recipes for making the worksheet look like you want it to. I have given you several control sequences here; you can also do these things from the Edit and Insert menus.

Make an execution group:

Ctrl-j makes one after the execution group or paragraph the cursor is in.

Ctrl-k makes one before the execution group paragraph the cursor is in.

Adding another > to an execution group

Use the arrow keys, or the mouse, to move the cursor just to the left of a > already in the group. Hit Enter and another one will appear just above.

Make a paragraph for text inside an execution group

Shift-Ctrl-j makes one after the cursor.

Shift-Ctrl-k makes one before the cursor (you also get one if you left arrow past the < sign and hit Enter)

Slip a paragraph for text between two execution groups

Click on the big [ at the left of the group; it will become a double line; then type Shift-Ctrl-k to get one before, Shift-Ctrl-j to get one after.

Delete a paragraph or execution group

Put the cursor in the paragraph or execution group to be deleted and type Ctrl-Del. To kill everything in the execution group you may have to do this several times.

Enter equations or expressions within text

Click on Sigma on the toolbar (or type Ctrl-r ) then watch the equation being typed in the window on the toolbar. The syntax for entering typeset mathematics is Maple's own syntax. For instance, to display the integral of the sine function from 0 to 1 you would type this: int(sin(x),x=0..1) but with Ctrl-r turned on, like this int(sin(x),x = 0 .. 1) . (Highlight this integral expression with the mouse and watch it appear as Maple code on the toolbar.) Hit Enter when it is complete, then click on T on the toolbar (or type Ctrl-t ) to go back to text mode. On some systems you will need to click on the check mark two buttons to the left of the math insertion window on the tool bar, followed by Ctrl-t (or clicking on T).

Split or join execution groups

See the Edit menu on the toolbar.

Remove all of the blue Maple output from the worksheet

See the Edit menu.

Close all of the sections and subsections in a worksheet

See the bottom of the View menu on the toolbar.

Removing the output and closing all of the sections fully restores this book to its original condition.

Other interesting tricks

Explore the toolbar and see what's up there. Of special interest are:

(a) Tile in the Window menu allows you to see the worksheet and do your assignment in side-by-side windows. Cascade under Window overlays them.

(b) You can get bold, italic, and underlined text with B , I, and u on the toolbar.

(c) Use the magnifying glass icons on the toolbar to change the size of the type.

(d) Notice the curvy arrow icons on the toolbar--they undo the last operation and redo the last undo.

(e) The stop sign will kill a calculation that has gone on so long you can't stand it anymore.

Problem 1.2

Open a new worksheet. At the top of the worksheet, above the first execution group, open up some white space and put in a bold title that says Problem 1.2. Below this title, in italics, put your name. Then expand the execution group so that it contains four >'s instead of just one and put comment lines that say "Comment 1", "Comment 2", etc., above each >.

Go to top of section

Online help

You probably already know how to use online help in programs, so when you click on the Help icon at the top of the page you will be in familiar territory. But there is a quicker way to get help directly at the Maple prompt: just use the question mark. For example, suppose you are pretty sure that Maple knows how to find the prime factors of big numbers, but you don't know the command. Try this.

> ?factor;

When you do you will find that this is the wrong command because it does algebra on polynomials. But if you read a bit, and look at the helpful See Also links at the bottom of the page you will see that the command you want is ifactor , so you either go there or use

> ?ifactor;

Now help will tell you that this is just what you want, and you can try

> ifactor(5040);

``(2)^4*``(3)^2*``(5)*``(7)

>

You can find lots of interesting stuff in Maple this way; happy hunting. And remember that the quick way to kill the help windows is with Ctrl-F4.

Problem 1.3

Use online help to find the Maple commands for integrating a function and for taking a derivative of a function.

-----------------------------------------------------------------------

Problem 1.4

Use online help to find the Maple command for taking the second derivative of a function.

------------------------------------------------------------------------

Go to top of section

Special constants

Debugging

There are several constants pre-loaded in Maple that are useful for physics. They are:

> Pi;I;infinity;

Pi

I

infinity

Pi is the number Pi to about as many significant figures as you want. To see its digits, use the Maple command evalf to convert a number to floating point form

> evalf(Pi,100);

3.1415926535897932384626433832795028841971693993751...

and you should be impressed. I is the imaginary unit, i.e., I = sqrt(-1) ; try executing

> sqrt(-5);

I*sqrt(5)

Infinity is, of course, not a number, but an idea, and only makes sense in limits. And Maple does the right thing in calculations involving limits, like

> limit(exp(-x),x=infinity);

0

or

> sum('1/2^n','n'=1..infinity);

1

>

We will do more of this kind of thing in Chapter 4.

Problem 1.5

Compare the Maple commands cos(pi) and cos(Pi) by trying them in an execution group. Explain why they don't behave the same way. (This issue will be discussed in more detail in the section on variable names).

----------------------------------------------------

Problem 1.6

Calculate the complex division problem (3+4i)/(7-6i) in a Maple execution group.

----------------------------------------------------

Problem 1.7

Calculate the limit, as x approaches infinity, of the expression (3-5x)/(7+3x) using a Maple execution group.

----------------------------------------------------

Go to top of section

Variable names

Debugging

Like all other modern computer languages, Maple allows you to name a variable just about anything you want, with some exceptions. In C and Fortran, for instance, you can't use "sin" as a variable name because this name is reserved for the sine function. You can probably think of other obvious reserved names like this ("cos", "tan", "log", etc.), but there are only about a hundred of these and you have the whole alphabet at your disposal, so it's not a big problem. In Maple you have to be more careful because there are about 3000 commands whose names are reserved for system use. But Maple will tell you if you have made a bad choice, and the possibilities for naming variables are still nearly endless.

Now let me warn you about a bad habit into which this naming freedom seems to have led your generation of computer users. Here is how some students I have worked with would write Newton's law of universal gravitation in a computer code:

Newtons_Gravitational_Constant*Mass_1*Mass_2/Distance_Between_The_Masses^2

Here is what this would look like in a Maple execution group:

> Newtons_Gravitational_Constant*Mass_1*Mass_2/Distance_Between_The_Masses^2;

Newtons_Gravitational_Constant*Mass_1*Mass_2/(Dista...

Now look; this form is certainly well documented, but you are going to spend a great deal of your life in programming typing code and reading code that has already been typed. Avoid clutter like the flu! Here's how I would suggest you write it in Maple:

> G*m1*m2/r12^2;

G*m1*m2/(r12^2)

>

The prosecution rests. I don't know who is responsible for the current popularity of the underscore character in variable names, but if I were you I would use it very sparingly, if at all. If I were programming Maple and choosing variable names, I would choose them to be as much like the symbols used in physics textbooks and research papers as possible. These would be things like a, m, F, c, q, L, h, etc..

But Maple has the ability to go even further toward the standard physics style because it has Greek letters! To get them just write out their names in English, as in the example below.

> alpha*beta/delta;

alpha*beta/delta

The capital Greek letters are also available, and even though some of them look like English capital letters, they are not the same, as you can see in the example below:

> Alpha*A;Beta+B;Chi/Gamma;

Alpha*A

Beta+B

Chi/Gamma

Well, OK; not all of the Greek capital letters are produced this way. Some of them you do this way

> CHI;

CHI

You can get all of them by creatively switching between a capital letter first and all capitals. If you persevere you can work in Maple with beautifully typeset equations just like you see in your textbooks. (And if you don't want to memorize their spellings and capitalizations, click on View, Palettes, Symbol Palettes and you will have a table of symbols you can get with the mouse.)

Note that a few are not available for your use:

> gamma:=4;Chi:=3;

Error, attempting to assign to `gamma` which is protected

Error, attempting to assign to `Chi` which is protected

>

These two, and possibly others, are used by the system. It may be possible to unassign them so that they are available for your own use, but I recommend against it. The more you work strictly within the Maple system the better off you will be; or in the language of Sunday afternoon in America, "take what the defense gives you."

Also avoid putting subscripts on variables, even though Maple's typesetting ability will let you do it. For instance you might want to work with the variables x[1] and x[2] which you get by doing this in Maple

> x[1]:=1;x[2]:=2;

x[1] := 1

x[2] := 2

They look great, but now watch what happens if you give x a value, then display x[1]

> x:=3;

x := 3

> x[1];

3[1]

>

I think we can all agree that this is not going to help us do mathematics. So if you want to code x[1] in Maple, call it x1. And as you choose variables, experiment a little with the names and try for elegance and simplicity.

Problem 1.8

Set the variable theta to have the value 5/3 and then coax the Maple command cos(theta) into giving you cos(5/3) as a floating point number.

-----------------------------------------------------------

Go to top of section

What can a variable represent?

Debugging

In standard computing languages like Fortran, C, and Matlab variables can only represent a limited number of different things, like integers, floating point numbers, complex numbers, and character strings, to name nearly all of them. But in Maple there are over 100 different things a variable can represent. This makes life much more complicated. For instance, in Fortran or Matlab the statement

a=5

would assign to the variable a the value 5. But in Maple the statement

> a=5;

a = 5

doesn't do assignment at all. Instead it is just the really stupid equation a = 5 . Maple is capable of solving this equation and discovering that a is 5, but it is not a statement that assigns a value. In order that Maple be able to work directly with equations (expressions containing the symbol =), the assignment statement has been given a different form. To assign to variable a the value 5 the Maple statement would be

> a:=5;

a := 5

One of the clearest ways of indicating the difference is to note that the following statement in Maple makes sense:

> Eq:=b=5;

Eq := b = 5

This statement means that the variable Eq contains the equation b = 5 . Here's a less dumb example:

> Eq2:= x^2 + y^2 = R^2;

Eq2 := 9+y^2 = R^2

Well, this probably looks a little strange; how come that 9 is there instead of an x? Well, maybe it isn't, depending on how you got here, but if you get a 9, here's why. In the last section on variable names x was set to 3, and Maple remembers forever. This will bite you over and over. The quickest way to cure it if you don't care about the stuff you have done before is to just restart Maple, like this:

> restart;

Now use the mouse to move the cursor back up to the Eq2 assignment, click on the red text, and it will execute properly. Note that this works even though the restart is below the Eq2:=... . Maple is not like C or Matlab. Order in the worksheet is not what's important--order in time spent at the keyboard is what matters.

So, what are the possible things that a variable can represent? The subsections given below are a partial list of the ones you are most likely to encounter. They are just Maple examples without comment. We will discuss each one in detail sometime during the course. To get a full look at what's possible, use

> ?type

And if you are confused about the type of, say, a variable named a, you can use the Maple command whattype(a).

Problem 1.9

On a clean worksheet use the Maple command b:=a=5 and then use the type command to check the type of b by using the commands type(b,integer), type(b,float), and type(b,equation) . Explain why the results of these three commands make sense to Maple.

--------------------------------------------------------------------------------

The sections below contain examples of the most important data types we will be using in this book.

Complex numbers

Note that I = sqrt(-1) .

> cn1:=(1+3*I)*(5-2*I);

cn1 := 11+13*I

Equations

> Eq1:=sin(x)=x;

Eq1 := sin(x) = x

Floating point numbers

Maple usually keeps 10 significant figures in floating point (real number) calculations. But you can increase it by changing the value of the Maple constant Digits , like this:

> f1:=4./3.;

f1 := 1.333333333

> Digits:=50;

Digits := 50

> f1:=4./3.;

f1 := 1.3333333333333333333333333333333333333333333...

> Digits:=10;

Digits := 10

Expressions and functions

An expression looks like what you would probably call a function, but there is a subtle difference. An expression is a combination of variables and Maple functions like this

> Fn1:=cosh(x^3)/(1+x^2);

Fn1 := cosh(x^3)/(1+x^2)

The reason it isn't a function is because of what you have to do to evaluate it for a specific value of x: Fn1(x) doesn't work! Instead you have to assign x a value like this

> x:=2.;

x := 2.

then evaluate Fn1

> Fn1;

298.0958322

A Maple function is defined with this syntax

> Fn2:=x->cosh(x^3)/(1+x^2);

This does behave like a function because you give it an argument and it gives you an answer back

> Fn2(2.);

298.0958322

Or you can define a function with multiple arguments like this

> Fn3:=(x,y,z)->x*y^2*z^3;

> Fn3(1,2,3);

108

Hence, the -> function notation makes functions like you are used to from math classes. So why would you even want to mess with expressions? Because Maple often has an easier time doing algebra with them, integrating them, differentiating them, plotting them, and using them to build differential equations. So you have to get used to both. I try to remember it this way: an expression looks like a function in a math book; a function is a machine that takes input and gives back output.

Integers

> I1:=12345678987654321;

I1 := 12345678987654321

Matrices

> M1:=matrix([[1,2],[3,4]]);

M1 := matrix([[1, 2], [3, 4]])

Polynomials

> P1:=y^3+y^2+y-1;

P1 := y^3+y^2+y-1

Strings

> S1:="Mary had a little lamb.";

S1 :=

Vectors

> V1:=Vector([1,2,3]);

V1 := _rtable[1347960]

Lists and sets

A list is a sequence of numbers, expressions, or any other legal data type enclosed in square brackets. They can be loaded either by hand or by means of the seq command.

> s1:=[1,2,4,6,8,12];

s1 := [1, 2, 4, 6, 8, 12]

> s2:=[seq(2*n^2-3*n+2,n=1..6)];

s2 := [1, 4, 11, 22, 37, 56]

Their elements can be referred to with Maple's square bracket subscript notation

> s1[3];s2[2..5];

4

[4, 11, 22, 37]

A set is similar to a list, but not quite. It is enclosed in curly brackets and Maple, instead of you, decides what order the elements should be listed in. The most important difference is that a list may contain repeated elements, but a set may not. Sets are often used in the arguments of Maple commands. In the example below note that the list stays the way it was defined while the set is re-ordered and reduced to unique elements.

> s1:=[1,3,2,6,4,3,2];

s1 := [1, 3, 2, 6, 4, 3, 2]

> s2:={1,3,2,6,4,3,2};

s2 := {1, 2, 3, 4, 6}

>

Go to top of section

Getting the answer

Debugging

Now we have come to the second most annoying thing about Maple: sometimes it doesn't feel like giving you the answer to your problem. Here are some examples.

Suppose you want to know the sine of the number 1 (in radians; all calculus is done in radians, so forget about degrees). You might think this would work:

> restart;

> sin(1);

sin(1)

This is not what we had in mind; we already know we want sin(1) , but what is the answer? Maple is having trouble here because it doesn't think it makes sense to take the sine of an integer constant; it expects floating point numbers. See what happens with the small addition of a decimal point

> sin(1.);

.8414709848

Difficulties like this are not always so easy to fix, so Maple provides a command to take care of it: evalf . It would be used in this example this way:

> sin(1);

sin(1)

> evalf(%);

.8414709848

>

The % sign means "the last result Maple calculated" (like Ans on some calculators). It is sin(1) in this case, and evalf stands for "evaluate as a floating point number". You will be using evalf a lot because Maple will be doing its symbolic thing when you want a numeric result. It's just the price you have to pay to have a calculator that is at home in both the symbolic and numerical worlds. Warning: if you get in the habit of using % routinely, you will routinely make mistakes. Only use it sparingly. Most of the time you should assign results to variable names, then work with these names to avoid confusion, like this:

> s:=sin(1);

s := sin(1)

> evalf(s);

.8414709848

Oh; and what's the number one most annoying thing about Maple? It doesn't give you very good error messages when you louse up. It tends either to just parrot back to you the thing you asked it to do, or it gives you gobbledygook like "Can't evaluate Boolean". But be patient; it is a great tool and it is improving all the time. It is definitely worth learning.

Go to top of section

Debugging (when bad things happen to good programmers)

Debugging

Everybody who writes or uses software has something in common--their programs don't work. And when this happens the most important skill you can have is the ability to find out exactly what went wrong. Here are some beginning tips for debugging Maple. More information is in the Debugging section at the end of the worksheet.

evalf (look at the numbers)

Suppose you wanted to know what the function sin(a^2*x^2)/(sin(a*x)^2) looks like. Maple's plot command is a wonderful way to see what functions look like, so you could define the function this way (the restart command is to make sure that this example is starting out with a clean slate)

> restart: f:=x-> sin(a^2*x^2)/sin(a*2)^2;

then use

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

Plotting error, empty plot

You will come to hate this error message. What it really means is that there is something wrong with the function f(x), but because Maple is so powerful and allows you to do all kinds of things, it can't tell you what the problem is. Hopefully at some point in time Maple will have better error messages. But you have a problem right now. When this happens, evalf can help. Let's check a particular value of this function to see if we can get a hint about what's wrong

> evalf(f(1.));

sin(1.*a^2)/(sin(2.*a)^2)

This is an error message in disguise. What it means is that Maple tried to give you a number back, but couldn't because you hadn't told it what a was. As soon as you give a a value, the plot will work. (Set a to be 5 in the execution group below and go back up and execute the plot.)

>

Here's another example. Suppose you forgot the value of sin(pi/2) and needed Maple to tell you, so you try

> s:=sin(pi/2);

s := sin(1/2*pi)

"No!", you scream, "GIVE ME THE NUMBER!" The Maple command for this would be

> evalf(s);

sin(.5000000000*pi)

This, believe it or not, is an error message. It says that Maple tried to give you the number, but couldn't because it didn't know what pi is. You have been done in by Maple's ability to deal with Greek letters. The symbol pi is just the Greek letter pi ; what you want is the ratio of circle area to the square of circle radius, which is Pi in Maple. When you do it this way it works

> sin(Pi/2.);

1

>

When Maple gives you back something unexpected, try to turn it into a number that you can check by using evalf . As you try to get a number out you will probably discover what the problem is.

Go to top of section

check := vs =

You will make this mistake 100 times at least: only use = when you are defining an equation; assignment, i.e., you want a to be 5, is done with a:=5 .

plot (make a picture)

Sometimes you will need to look at a lot more than just one number to see what went wrong, and the best way to look at a thousand numbers is to make a picture. For instance, suppose you tried to do the integral

> restart;

> int(sin(x)/(1-cos(x)),x=0..Pi);

infinity

You thought you were going to get a number, but Maple gave you infinity. You could use floating point arguments to check the function like this

> sin(1.)/(1-cos(1.));

1.830487722

but that looks fine. To check a whole bunch of values over the integration range, make a plot using Maple's command plot:

> plot(sin(x)/(1-cos(x)),x=0..Pi);

[Maple Plot]

>

Now you can see that the integrand is singular at x=0, so Maple was right: the answer is infinity. Making plots is a great way to debug.

assume (tie Maple down)

Sometimes Maple can't do what you want it to do because you are thinking about a specific problem and Maple is thinking generally. For instance, suppose you wanted to do the integral

> restart;

> int(exp(-a^2*x^2),x=0..infinity);

Definite integration: Can't determine if the integral is convergent.

Need to know the sign of --> a^2

Will now try indefinite integration and then take limits.

limit(1/2*sqrt(Pi)*erf(a*x)/a,x = infinity)

You wanted a formula containing a , but instead you got this mess. This time Maple gives you a hand--since Maple can handle complex numbers, it can't tell whether a^2 is positive or negative. It will give you the answer if you give it a little help with assume

> assume(a,real);

> int(exp(-a^2*x^2),x=0..infinity);

1/2*sqrt(Pi)/(sqrt(a^2))

>

Look the assume command up in online help; it will help you keep Maple under control.

Warning: Once you have used assume on a variable, however, you may have trouble having Maple give you numbers. The trouble happens when you assume something about a, use a in an expression and assign it to another variable (say b), then give a a value, and finally try to evaluate b. Observe:

> restart;

> assume(a,real);

> b:=cos(a);

b := cos(a)

> a:=2.;

a := 2.

> evalf(b);

cos(a)

Now watch what happens to the same sequence without the assume

> restart;

> b:=cos(a);

b := cos(a)

> a:=2.;

a := 2.

> evalf(b);

-.4161468365

The lesson here is only to use assume when absolutely necessary.

Finally, you may need to assume two conditions on a variable, like both c>0 and c<1. Maple lets you do this in two ways. You can either put both conditions inside a single assume command like this

> assume(c>0,c<1);

or you can do it in two (or more) steps using the command additionally , like this

> assume(c>0);

> additionally(c<1);

The reason you can't just use two assume commands is that whenever you use assume on a variable it erases all previous assumptions set on that variable.

>

restart (punt)

Sometimes Maple has a hard time giving you what you want because it has become so cluttered with everything you have been doing in a session that things you have forgotten, but that it remembers, interfere with what you are trying to do. I can only give you a simple example here, but this kind of thing happens all the time and it is quite often easier to just start over than to try to figure out what went wrong. Suppose you were exploring the Bessel function J[0](x) by checking a few values like this

> restart;

> x:=1.5;BesselJ(0,x);

x := 1.5

.5118276717

And then after trying a few different values of x , you decided to plot the function like this

> plot(BesselJ(0,x),x=0..5);

Error, (in plot) invalid arguments

This is a pretty mysterious error message, and you have to know quite a bit about Maple to be able to tell what's wrong. But if you do this

> restart: plot(BesselJ(0,x),x=0..5);

[Maple Plot]

>

all is well. This is the Maple equivalent of ctrl-alt-del on the PC, and you will be using it regularly.

Go to top of section

Cool stuff you can do right now

Even knowing the little bit you have learned right now you can do some rather amazing things. Open each subsection and see what you can do.

Integration

Debugging

Integration is done with the int command.

Here's an indefinite integral int(exp(-x)*sin(x),x) :

> restart;

> int(exp(-x)*sin(x),x);

-1/2*exp(-x)*cos(x)-1/2*exp(-x)*sin(x)

Here's a definite integral int(exp(-x)*sin(x),x = 0 .. 1)

> s1:=int(exp(-x)*sin(x),x=0..1);

s1 := -1/2*exp(-1)*cos(1)-1/2*exp(-1)*sin(1)+1/2

This is a perfectly valid expression, but perhaps you want a number?

> evalf(s1);

.2458370070

Here's an integral Maple can't do

> s2:=int(exp(-x^4)*cos(x),x=0..1);

s2 := int(exp(-x^4)*cos(x),x = 0 .. 1)

so it just prints it nicely and lets you worry about how to get an actual number out. You do this by asking Maple to do it numerically

> evalf(s2);

.7363519309

>

Problem 1.10

Find the numerical answer to int(exp(sqrt(x)),x = 0 .. 2) . Put a comment on the same line as the command with Maple's # notation.

-----------------------------------------------------------

Go to top of section

Differentiation

Debugging

Take the derivative of any function using diff

> restart;

> d1:=diff(sin(x)/sqrt(1+x^2),x);

d1 := cos(x)/(sqrt(1+x^2))-sin(x)*x/((1+x^2)^(3/2))...

Perhaps you don't like the look of this and would rather have a common denominator. This is called normal form and can be obtained this way (we will do more of this in Chapter 9)

> normal(d1);

(cos(x)+cos(x)*x^2-sin(x)*x)/((1+x^2)^(3/2))

You can do second derivatives too

> d2:=diff(exp(-x)*tan(x),x$2);

d2 := exp(-x)*tan(x)-2*exp(-x)*(1+tan(x)^2)+2*exp(-...

Maybe you think this could look prettier? Try

> simplify(d2);

3*exp(-x)*tan(x)-2*exp(-x)-2*exp(-x)*tan(x)^2+2*exp...

then try to pull out the common exponential factor with

> factor(%);

exp(-x)*(3*tan(x)-2-2*tan(x)^2+2*tan(x)^3)

and then get the polynomial in tan(x) to be in the right order

> sort(%);

(2*tan(x)^3-2*tan(x)^2+3*tan(x)-2)*exp(-x)

And now that I like the final answer I will assign it to d2. This is one of the few times that I use the previous answer variable % . It is useful here because if one of the algebra commands I use to get an improved form doesn't work, I haven't messed up what's in d2, so I can just keep trying things until I like what I get.

> d2:=%;

d2 := (2*tan(x)^3-2*tan(x)^2+3*tan(x)-2)*exp(-x)

These algebra commands, and more, are discussed in Chapter 9. During the semester you should get used to going to Chapter 9 and looking around whenever you want Maple put an expression in a form you like better.

>

Problem 1.11

Take the first derivative of the function cos(cos(cos(cos(x)))) . Put a comment about what you are doing in text within the execution group and above the diff command.

-----------------------------------------------------------

Go to top of section

Build a sequence

Debugging

In calculus you studied sequences of numbers that tend to a limit and infinite sums of such sequences. In Maple sequences are built with the seq command. It works this way

> restart;

> s:=seq((5+n)/(3+n),n=1..50);

s := 3/2, 7/5, 4/3, 9/7, 5/4, 11/9, 6/5, 13/11, 7/6...
s := 3/2, 7/5, 4/3, 9/7, 5/4, 11/9, 6/5, 13/11, 7/6...

or

> evalf(s);

1.500000000, 1.400000000, 1.333333333, 1.285714286,...
1.500000000, 1.400000000, 1.333333333, 1.285714286,...
1.500000000, 1.400000000, 1.333333333, 1.285714286,...
1.500000000, 1.400000000, 1.333333333, 1.285714286,...
1.500000000, 1.400000000, 1.333333333, 1.285714286,...
1.500000000, 1.400000000, 1.333333333, 1.285714286,...

so it is clear that the sequence is approaching a limit of 1.

Or you can build a sequence of expressions, like the terms of a power series. Here are the terms in the series for the exponential function

> seq(x^n/n!,n=1..20);

x, 1/2*x^2, 1/6*x^3, 1/24*x^4, 1/120*x^5, 1/720*x^6...
x, 1/2*x^2, 1/6*x^3, 1/24*x^4, 1/120*x^5, 1/720*x^6...
x, 1/2*x^2, 1/6*x^3, 1/24*x^4, 1/120*x^5, 1/720*x^6...

>

Problem 1.12

Generate the first 15 terms of the sequence defined by s[n] = diff(cos(x)/(1+x),`$`(x,n)) . Put a comment about what you are doing in text below the seq command, but within the same execution group.

-----------------------------------------------------------

Sum a series

Debugging

Find a formula for the sum of the integers raised to the 6th power using sum

> restart;

> s1:=sum(k^6,k=1..n);

s1 := 1/7*(n+1)^7-1/2*(n+1)^6+1/2*(n+1)^5-1/6*(n+1)...

Find the result of summing the reciprocals of the integers raised to the 6th power from 1 to infinity

> s2:=sum(1/n^6,n=1..infinity);

s2 := 1/945*Pi^6

then convert this to a numerical value

> evalf(s2);

1.017343063

>

Problem 1.13

Find the sum of the reciprocals of the squares of the odd integers from 1 to infinity . Put a comment about what you are doing in a separate paragraph above and outside the execution group containing the sum command.

-----------------------------------------------------------

Taylor series

Debugging

One of the most useful tools used by physicists to get approximate answers to difficult problems is the Taylor series. You have probably forgotten this result, so here it is: any function f(x) which is infinitely differentiable can be approximated in the neighborhood of x = a by a polynomial in ( x-a ) which is given by Taylor's famous formula

f(x) = f(a) + f'(a)(x-a) + f''(a) (x-a)^2/2! + f'''(a)(x-a)^3/3! + ...

This is very useful in getting approximations. For instance, the quantity 1/sqrt(1-v^2/(c^2)) appears all the time in relativity theory. It is sometimes nice to have an approximate form for this formula if v/c is small. Use the taylor command to find it.

> restart;

> taylor(1/sqrt(1-x^2),x,5);

series(1+1/2*x^2+3/8*x^4+O(x^6),x,6)

>

where the 5 means get terms up through x^5 in the expansion. The term O(x^6) in the answer means that the error in this expansion is of order x^6

.

Problem 1.14

Find an approximate formula for the function exp(cos(x)) including terms up through x^10 . Display the coefficients of the series in both rational and floating point form. Put a comment about what you are doing in a text paragraph outside and below the execution group containing the taylor command.

-----------------------------------------------------------

Go to top of section

Plot functions

Debugging

If you want to quickly find out what some function that you have run across looks like, use plot

> restart;

> plot(exp(sin(x)),x=0..50);

[Maple Plot]

>

Problem 1.15

Make a plot of the function exp(-x/25)*cos(x) from x = 0 to x = 100 . Then put a comment about what you are doing in a paragraph between the two execution groups.

-----------------------------------------------------------

Solve hard equations

Debugging

Suppose you need a solution of exp(-x) = x . Use solve on the equation

> restart;

> sol:=solve(exp(-x)=x,x);

sol := LambertW(1)

Well, this is an answer in terms of some function you have never heard of when what you really wanted was just a number. No problem; just use

> evalf(sol);

.5671432904

Or if you already know that there isn't going to be a symbolic solution and you just want a number, you could tell Maple to just numerically solve this equation with Maple's numerical equation solver fsolve , telling Maple to start looking for a solution near x=1:

> fsolve(exp(-x)=x,x=1);

.5671432904

If you don't give it a good guess it may take longer to get the answer or it may get lost and go to infinity instead of finding the answer.

Problem 1.16

Find the solution of the equation cos(x) = x . Put a comment about what you are doing in a paragraph within the execution group just above the command. Within this paragraph of text use Maple's math mode ( Sigma on the toolbar) to include the equation cos(x) = x .

Maple will also solve equations (even systems of equations) for you symbolically. For example, here is how Maple solves the quadratic equation symbolically:

> Q:=a*x^2+b*x+c=0;

Q := a*x^2+b*x+c = 0

> solve(Q,x);

1/2*(-b+sqrt(b^2-4*a*c))/a, 1/2*(-b-sqrt(b^2-4*a*c)...

And here's the symbolic solution of the general problem of two equations in two unknowns, with x and y unknown and a-f as the coefficients:

> E1:=a*x+b*y=e;E2:=c*x+d*y=f;

E1 := a*x+b*y = e

E2 := c*x+d*y = f

> solve({E1,E2},{x,y});

>

{y = (-a*f+e*c)/(b*c-d*a), x = (b*f-d*e)/(b*c-d*a)}...

You may find this an easier way of handling simultaneous equations than using Maple's linear algebra package.

>

-----------------------------------------------------------

Solve differential equations

Debugging

Suppose you need the two fundamental solutions of the second order differential equation

f'' + xf' +f = 0 where ' denotes differentiation by x; use Maple's differential equation solving command dsolve

> restart;

> dsolve(diff(f(x),x$2)+x*diff(f(x),x)+f(x)=0);

f(x) = erf(1/2*I*sqrt(2)*x)*_C1/exp(1/2*x^2)+_C2/ex...

>

The variable _C1 is the arbitrary multiplier of the first fundamental solution and _C2 is the multiplier of the second. It involves a function erf(x) that you haven't encountered yet, but you will. Solving differential equations is a big subject and we will devote all of Chapter 7 to it.

Problem 1.17

Find the solution of the differential equation y' = x+y. After Maple finds the general solution, find the value of the arbitrary constant from the condition y(0)=1. Put a comment about what you are doing in a paragraph of text below and outside the execution group.

-----------------------------------------------------------

Maple can also handle the initial conditions for you, like this (using f(0) = 1 and diff(f,x)(0) = 2 ):

> Eq:=diff(f(x),x$2)+x*diff(f(x),x)+f(x)=0;

Eq := diff(f(x),`$`(x,2))+x*diff(f(x),x)+f(x) = 0

> dsolve({Eq,f(0)=1,D(f)(0)=2},f(x));

f(x) = -I*erf(1/2*I*sqrt(2)*x)*sqrt(Pi)*sqrt(2)/exp...

>

Handle matrices and solve systems of equations

Debugging

There is an entire package in Maple devoted to matrices, vectors, and linear algebra. We will spend Chapter 5 on this subject, but here is an example of what can be done. Let's solve the linear system of equations

x + 2y + 3z = 6

4x + 5y + 6z = 15

7x + 8y + 10z = 25

which has been carefully built so that its solution is [x,y,z] = [1,1,1]. Maple would solve this system this way. First load the part of Maple's brain that knows how to do linear algebra with the command with(LinearAlgebra) . Then load the matrix with the matrix command, load the right-hand side vector with the vector command, and finally solve the system with the linsolve command.

> restart;

> with(LinearAlgebra);

[Add, Adjoint, BackwardSubstitute, BandMatrix, Basi...
[Add, Adjoint, BackwardSubstitute, BandMatrix, Basi...
[Add, Adjoint, BackwardSubstitute, BandMatrix, Basi...
[Add, Adjoint, BackwardSubstitute, BandMatrix, Basi...
[Add, Adjoint, BackwardSubstitute, BandMatrix, Basi...
[Add, Adjoint, BackwardSubstitute, BandMatrix, Basi...
[Add, Adjoint, BackwardSubstitute, BandMatrix, Basi...
[Add, Adjoint, BackwardSubstitute, BandMatrix, Basi...
[Add, Adjoint, BackwardSubstitute, BandMatrix, Basi...
[Add, Adjoint, BackwardSubstitute, BandMatrix, Basi...
[Add, Adjoint, BackwardSubstitute, BandMatrix, Basi...
[Add, Adjoint, BackwardSubstitute, BandMatrix, Basi...

(If you don't want to see all of this stuff that printed because we pulled in Maple's linear algebra package, put a colon at the end instead of a semicolon.)

> A:=Matrix([[1,2,3],[4,5,6],[7,8,10]]);

A := _rtable[13515488]

> b:=Vector([6,15,25]);

b := _rtable[13967964]

> c:=LinearSolve(A,b);

c := _rtable[13968004]

>

Problem 1.18

Jack is twice as old as Jill. Jill's age added to Jack's age is the same as Joan's age. The sum of their three ages is 48. How old is each person? Solve this problem by copying and modifying the above example. Put a comment about what you are doing between the Vector and LinearSolve execution groups. If your copy of the code above doesn't have these in separate execution groups, split them by looking in the edit menu.

-----------------------------------------------------------

Do algebra

Debugging

This is a very big topic and one of the main things Maple was designed to do. Chapter 9 has a description of common algebra commands that you will be using throughout this course. You can use Chapter 9 as a reference whenever Maple gives you an answer whose form doesn't impress you. Take a few minutes now and read through Chapter 9, down to the section on algebra with matrices. Don't try to understand in detail everything that you read; just become familiar with what's available in Chapter 9 so you know where to look when problems come up later. Then come back here and do the problem below. (Don't do the problems at the end of Chapter 9.) Chapter 9

Problem 1.19

Use Maple commands to put the expression 1/x-x/(x-1)+x/(x+1) into a simpler form. Put a comment about what you are doing in text above and outside the first execution group.

-----------------------------------------------------------

Go to top of section

Go to top of section

Go to top of chapter