Introduction to Maple
For Physics Students
Maple 11
Ross L. Spencer
Brigham Young University
Copyright 2007
Ross L. Spencer and Brigham Young University
Chapter 1: Getting Started
Introduction
Index
Debugging
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.
Before you begin, however, take a look at the items on the left side of the worksheet. These are palettes from which you can select commands for integrating, differentiating, summing, building matrices, etc. These palettes amount to a sort of symbolic help menu, so if you forget the form of a command, go looking for it in the palettes at the left of the worksheet.
Right Click: Maple's answers to the math problems you will give it will appear in blue on the screen. To see what things Maple might be able to do to this answer (integrate it, differentiate it, etc.) just right click on the blue answer and a menu of possibilities will appear. If you click on these menu items the Maple commands you need will appear in fill-in-the blank style. For example, here is the sine function. Place the cursor on the red sin(x) below and press Enter. Right click on the blue version of sin(x) that appears, select Differentiate, and then x to have Maple take its derivative with respect to x. You will also be able to see the Maple command that does the job, which will help you learn Maple syntax, and you will see that the answer will be assigned to a variable name that starts with R. You will understand this part the of the result better very soon.
Worksheet style
Maple has two different styles: Worksheet style and Document style. This book is written in Worksheet style with certain choices for the display of input and output that you will probably get used to, so you may want to make the same choices in your own worksheets that I have made here. To set these preferences, do the following:
(1) Click on Tools on the toolbar at the top, then select Options.
(2) Select Display, then set Input Display to Maple Notation and set Output Display to 2-D Math Notation.
(3) Back up and select Interface, then in the box Default format for new worksheets select Worksheet.
Execution groups
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 left 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 perhaps a mathematical piece of text); the red stuff on the line with > is a Maple command; and the blue stuff is the Maple result. To see an example put the cursor on the > restart; below and press Enter twice. (You will learn about restart shortly.)
Find the sine of divided by 4, or
Notice that each Maple command must end with a semicolon (in which case the answer prints in blue) or a colon (in which case the command executes, but the printing of the answer is suppressed). To see how this works, change the semicolon ; in the sin(Pi/4) line above to a colon : and see what happens when you execute the command by putting the cursor on the red command line and pressing Enter.
As you can see in this text, a Maple worksheet can contain both commands and text. 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.
There are two places where you can put your comments: just before the Maple command and just after it. To place a comment just before the red command sin(x)/(1+x^2) below, put the cursor just after the ; in the line and hold down the keys Shift-Ctrl-k. A little bit of white space will open up above the command into which you can type either text or an equation. As an example, in the execution group below enter the following comment:
This is the function .
To obtain the nice fraction with in the numerator and in the denominator type the text "This is the function" first, then at the upper left corner of the toolbar where you can see a Text button and a Math button, click on the Math button (or press Ctrl-r). If you start to type sin(x)/(1+x^2) the fraction will appear on the screen. This puts you into math entry mode and when you click on the Text button , or press Ctrl-t, you will come back into text mode and your math expression will be nicely formatted in your comment. And if you use Shift-Ctrl-j instead, the white space for entering a comment will be below the Maple command. Try putting comments in the line below until you see how it works.
Maple will also allow you to use subscripts and superscripts in math entry mode. For instance, to make this expression
You would have to do the following: (1) Use Ctrl-r to get into math entry mode (2) type the characters (a (3) type the underscore character _ to go into subscript mode and then type 1 (4) use the ↑ key to get out of subscript mode (5) type + b (6) use _ again and type 3 (7) use ↑ again (8) type )/ to start on the denominator (9) type (c_4↑ (10) type + d_5↑) (11) use Ctrl-t to get out of math entry mode. Take a minute now and practice doing this in the white space below. Superscripts (which are the same as raising to a power) are obtained by using ^ and ↓ following the pattern for _ and ↑ .
Now hang in there, you're about to actually do something real. There is an execution group just below this section of text. Put text that says Kindergarten stuff above the > sign in this execution group (put the cursor in the group and use Shift-Ctrl-k) then move the cursor back into the execution group (or use ↓ ); then put 1+1 after the > sign and hit Enter
You will find that in addition to seeing the answer in blue, you also got a warning about a semicolon--always remember to end each Maple command with either a semicolon (print the answer) or a colon (don't print the answer).
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 put extra > lines inside a single execution group make a set of separate execution groups (create them either with Ctrl-j or Ctrl-k), then combine them by putting the cursor on the first one in the set and then joining them using F4. And if you have a set of combined execution groups, you can use F3 to split them up again. (These commands are also available under Insert and Edit on the tool bar.) Take a minute now and practice splitting and joining execution groups using F3 and F4 on the combined set below.
Oh, and also 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
If you need to delete an execution group the command Ctrl-Delete will do the job.
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 Maple 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. Simply move the cursor across each icon to see what each one is about.
And for further information on the the way the window is managed, click on Help and try the New Users tour.
Problem 1.1
Make an execution group and document it before the > sign with the comment:
Add the integers from 1 to 10.
Then build a Maple command line to calculate the answer to 1+2+3+...+10.
------------------------------------------------------------------------------------
Go to top of section
Quick guide to managing the worksheet
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 a new execution group after the execution group or paragraph the cursor is in.
Ctrl-k makes a new execution group before the execution group or paragraph the cursor is in.
Adding another > to an execution group
If you want a single execution group to have multiple execution lines (>) in it, make a series of execution groups, then use F4 to join then together. F3 will split them apart (see below).
Make a paragraph for text inside an execution group
Shift-Ctrl-j makes white space after the cursor. Shift-Ctrl-k makes white space before the cursor.
Slip a paragraph of text between two execution groups
This is a problem. It used to be possible to do this, and you will see lots of examples of it in this book, including right here. Notice that this text you are reading is not part of any execution group. But even though Maple still runs worksheets that have nice book-like white space in them, it seems no longer to be able to produce such space. Hopefully this will be fixed in some future version. Here is the way it used to be done before version 9:
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
The syntax for entering typeset mathematics is similar to Equation Writer in Microsoft Word. For instance, to display the integral of the sine function from 0 to 1 you would type Ctrl-r and observe that a prompt of the form / shows up. Now select the definite integral template with the mouse from the Expression Palette at the left of the screen. Click on the various parts of the template and edit them to obtain
If you explore the palettes you will find all sorts of symbols that will come in handy when you want to document your work with mathematical expressions.
Making Maple do it your way
Suppose you want the answer to a problem to look a certain way, such as , for example. But when you do this in Maple it thinks this is a bad idea and does it this way instead:
You can bend Maple to your will by putting things inside single quotes, like this
Maple will still work with such a forced expression in the usual way.
Split or join execution groups
Open the Edit menu on the toolbar. Note that F3 splits and F4 joins. You might want to practice with these two shortcuts until you see how they work. These commands are useful if you want to have several execution lines in one paragraph like this:
To obtain this set make 3 execution groups using Ctrl-j and then use F4 to join them. To take them apart into separate groups again use F3.
Remove all of the blue Maple output from the worksheet
See Remove Output in the Edit menu on the toolbar.
Collapse all of the sections and subsections in a worksheet
See the bottom of the View menu on the toolbar.
Removing the output and collapsing 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. I think everything looks better with magnification level 2.
(d) Notice the curvy arrow icons on the toolbar--they undo the last operation and redo the last undo.
(e) The stop sign with an open hand in it 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, in 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 create an execution group that contains four >'s instead of just one and put comment lines that say "Comment 1", "Comment 2", etc, above each of the >'s.
Maple help
You probably already know how to use help menus, so when you click on the Help icon at the top of the page you will be in familiar territory. Also remember that right clicking on blue results can help you know what your possibilities are. 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.
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
Now help will tell you that this is just what you want, and you can try
You can find lots of interesting stuff in Maple this way; happy hunting.
Problem 1.3
Use Maple help to find the Maple commands for integrating a function and for taking a derivative of a function.
-----------------------------------------------------------------------
Problem 1.4
Use Maple help to find the Maple command for taking the second derivative of a function.
------------------------------------------------------------------------
Special constants
There are several constants pre-loaded in Maple that are useful for physics. They are:
Pi is the number 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 (the second argument of 100 instructs Maple to give you 100 decimal places)
and you should be impressed. I is the imaginary unit, i.e., ; try executing
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
or
would be evaluated like this:
We will do more calculations like this 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 in a Maple execution group. (Note: unless you are careful here you will get an error. First, remember that is I in Maple. Then notice that really mean so remember to put the multiply signs in, i.e., 4*I.)
Problem 1.7
Calculate the limit, as x approaches infinity, of the expression using a Maple execution group. (Again--remember that really means
Variable names
Like all other modern computer languages, Maple allows you to name a variable just about anything you want, with a few 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:
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 and carpal tunnel syndrome! Here's how I would suggest you write it in Maple:
I don't know the origin of the current popularity of the underscore character and capitalization in variable names, but if I were you I would use this style very sparingly, if at all. When I program I choose variable names 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.
The capital Greek letters are also available, and even though some of them look like English capital letters, they are not quite the same, as you can see in the example below:
Well, OK; not all of the Greek capital letters are produced this way. Some of them you do this way
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 use the Greek palette on the left side of your screen to access these symbols with the mouse.)
Note that a few are not available for your use:
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 and which you can get by doing this in Maple
They look great, but now watch what happens if you give a value, then display
I think we can all agree that this is not going to help us do mathematics. So if you want to code 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 into giving you cos(5/3) as a floating point number.
Maple will also let you put special characters in the name of a variable, but you have to use a special syntax. For example, suppose you wanted to define an expression f, then assign its derivative to the symbol f'. You would do it like this:
The backward quote marks around f' tell Maple that you are going to use a special character ( ' in this case) in the variable name and instructs Maple to accept this name without complaint.
-----------------------------------------------------------
What can a variable represent?
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
doesn't do assignment at all. Instead it is just the really stupid equation . Maple is capable of solving this equation and discovering that a is 5, but it is not a statement that assigns a value to the variable a. To help Maple work directly with equations (expressions containing the symbol =), the assignment statement has been given a different form. To assign to variable the value 5 the Maple statement would be
One of the clearest ways of indicating the difference is to note that the following statement in Maple makes sense:
This statement means that the variable contains the equation . Here's a less dumb example:
Well, this probably looks a little strange; why is there a 9 instead of an x? Well, maybe there isn't, depending on how you got here, but if you get a 9 in the result of this command when you execute it, 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 calculations you have done before, is to just restart Maple, like this:
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
and scroll down to the huge list of variable types (and other stuff) at the bottom of the help window. If you were to be confused about the type of, say, a variable named a, you could use the Maple command whattype(a).
To check the type of our equation Eq2 above you would type
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 .
Equations
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:
Notice that e-11 is the way to do scientific notation exponents--don't use 10^(-11). All programming languages and calculators do it this way so you should become familiar with this notation.
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
The reason it isn't a function is because of what you have to do to evaluate it for a specific value of x: Typing Fn1(x) doesn't work! Instead you have to assign x a value like this
then evaluate Fn1
A Maple function is defined with this syntax
This does behave like a function because you give it an argument and it gives you an answer back
Or you can define a function with multiple arguments like this
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: a Maple expression looks like a function in a math book; a Maple function is a machine that takes input and gives back output.
Integers
After the blue answer appears, right click on it to see what Maple can do to this number--for instance, select Integer factors and watch what happens.
Matrices
Polynomials
Strings
Vectors
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.
Their elements can be referred to with Maple's square bracket subscript notation
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.
Getting the answer
Now we have come to probably the most frustrating 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:
This is not what we had in mind; we already know we want , but what is the answer? Maple is having trouble here because it thinks that the sin(1) makes perfect sense--why would you want anything else? It doesn't know that you are a physicist focused on numbers with decimal points. See what happens with the small addition of a decimal point
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:
The % sign means "the last result Maple calculated" (like Ans on some calculators). It is 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:
Debugging (when bad things happen to good programmers)
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 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)
then use
The error message tells us that Maple had trouble turning this formula into numerical values, which it needs to make a plot. A way of seeing what's wrong is to use evalf on a function value, like this:
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 was. As soon as you give 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 and needed Maple to tell you, so you try
"No!", you scream, "GIVE ME THE NUMBER!" The Maple command for this would be
This, again, is an error message. It says that Maple tried to give you the number, but couldn't because it didn't know what is. I have led you into error by using Maple's ability to deal with Greek letters. The symbol pi is just the Greek letter ; 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
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.
check := vs =
You will make this mistake over and over: 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
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
but that looks fine. To check a whole bunch of values over the integration range, make a plot using Maple's command 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
You wanted a formula containing , but instead you got this limit expression. This time Maple gives you a helpful error message--since Maple can handle complex numbers, it can't tell whether is positive or negative. It will give you the answer if you give it a little help with assume
Look up the assume command up in help; it will help you learn how to obtain useful results from Maple.
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:
Now watch what happens to the same sequence without the assume
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
or you can do it in two (or more) steps using the command additionally, like this
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 (time to punt)
Sometimes Maple has a hard time giving you what you want because it has become cluttered with everything you have been doing in a session. You have forgotten some of it, but Maple remembers, and this interferes with your work. 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 rather than trying to figure out what went wrong. Suppose you were exploring the Bessel function by checking a few values like this
And then after trying a few different values of , you decided to plot the function like this
This is a pretty mysterious error message, and you have to be familiar with Maple to be able to tell what's wrong. But if you do this
all is well. The restart command is the Maple equivalent of rebooting, and you will be using it regularly. (Note: the plot failed because we tried to plot with the variable x, which had been given a value of 1.5 just before the plot. Using an unassigned variable name works just fine:)
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
Integration is done with the int command.
Here's an indefinite integral :
Or, if you don't know the command to integrate, you could just type the function into an execution group like this, then right click on it and select Integrate.
As you use the right-click feature Maple will always assign the result to a variable beginning with R. The first time you use it the variable will be R; the next time it will be R0, then R1, then R2, etc.
You can also select the integration command from the Expression palette at the left of the worksheet. Put the cursor in the execution group below and select the integration symbol from the Expression palette. The command will appear and only needs some editing from you to do your problem.
Here's a definite integral
This is a perfectly valid expression, but perhaps you want a number?
Here's an integral Maple can't do
so it just prints it nicely and lets you worry about how to get an actual number out. You do this by using evalf to ask Maple to do it numerically
Problem 1.10
Find the numerical answer to . Put a comment on the same line as the command with Maple's # notation.
Differentiation
Take the derivative of any function using diff
(Or use right-click if you don't remember the command)
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)
You can do second derivatives too
Maybe you think this could look prettier? Try
and then put the polynomial in in the usual order of high powers down to low ones by using
And now that we have a nice 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 get what I want.
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 . Put a comment about what you are doing in text within the execution group and above the diff command.
Build a sequence
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
which gives us a hint 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
Problem 1.12
Generate the first 15 terms of the sequence defined by . Put a comment about what you are doing in text below the seq command, but within the same execution group.
Sum a series
Find a formula for the sum of the integers raised to the 6th power using sum
Find the result of summing the reciprocals of the integers raised to the 6th power from 1 to
then convert this to a numerical value
Problem 1.13
Find the sum of the reciprocals of the squares of the odd integers from 1 to . Put a comment about what you are doing in a line of text above the execution group containing the sum command.
Taylor series
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 which is infinitely differentiable can be approximated in the neighborhood of by a polynomial in ( ) 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 appears all the time in relativity theory. It is sometimes nice to have an approximate form for this formula if is small. Use the taylor command to find it.
where the 5 means get terms up through in the expansion. The term in the answer means that the error in this expansion is of order .
And if you want to work with this polynomial approximation? You can convert this series to a polynomial with the command convert(...,polynom), like this:
Problem 1.14
Find an approximate formula for the function including terms up through . 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 just below the taylor command.
Plot functions
If you want to quickly find out what some function that you have run across looks like, use plot
Problem 1.15
Make a plot of the function from to . Then put a comment about what you are doing in a paragraph just above the plot command.
Problem 1.16
A charged disk of radius having uniform charge density produces an electric field along the z-axis (where the z-axis is the line perpendicular to the disk through its center) given by the integral expression
.
Find a simple algebraic expression for , then use , , and to make a plot of from to .
Note: when you need to enter numbers like these in scientific format you will make your code run faster and impress other programmers if you don't use 10 raised to a power. Instead, do it this way:
1e-6 and 8.854e-12
Solve hard equations
Suppose you need a solution of . Use solve on the equation
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
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:
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.17
Find the solution of the equation . 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 (use Ctrl-r) to include the equation .
Maple will also solve equations (even systems of equations) for you symbolically. For example, here is how Maple solves the quadratic equation symbolically:
And here's the symbolic solution of the general problem of two equations in two unknowns, with and unknown and through as the coefficients:
You may find this an easier way of handling simultaneous equations than using Maple's linear algebra package.
Problem 1.18
In the calculation of the way a Venturi tube works (see Serway, Example 15.13) Bernoulli's equation
and the equation of continuity
are to be solved simultaneously to obtain the following formula for :
Use Maple to obtain this result.
Hints: There are several things that can go wrong here. (1) You may get an ugly mess with % signs in it. If this happens go to Tools->Options->Display->Output Display and select 2-D Math Notation instead of Typeset Notation. (2) Even without the % signs you still have RootOf. You can force Maple to solve these quadratic equations by using the allvalues command. Look it up in online help to see how it works, then follow this example:
Even after you do this your answer won't look like the one in the problem above. To get closer use the command simplify(...,symbolic); . In this command ... is the expression you are trying to simplify.
Solve differential equations
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
The variable is the arbitrary multiplier of the first fundamental solution and is the multiplier of the second. It involves a function 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.19
Find the solution of the differential equation . After Maple finds the general solution, find the value of the arbitrary constant from the condition y(0)=1 by replacing in the solution with 0, replacing with 1, then solving the resulting equation for the unknown constant . Put a comment about what you are doing in a paragraph of text below and inside the execution group.
In the previous problem you had to work a little to get the initial conditions right. Maple can do this work for you, like this: ( using and in the differential equation
)
There will be lots more on this subject in Chapter 7.
Handle matrices and solve systems of equations
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 bring in the linear algebra package by using 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 LinearSolve command.
(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.)
Problem 1.20
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 commands. 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
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 skim 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.21
Use Maple commands to put the expression 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 chapter