MATH 1180 - Spring 2007 Introduction to Maple Logging in:

advertisement
MATH 1180 - Spring 2007
Introduction to Maple
1 Getting Started
Logging in: This is what you do to start working on the computer. If your machine seems to be
asleep, jiggle the mouse to wake it up. If necessary, hit the "enter" key to get the cursor into the
"login name" box. Your login name is made as follows: All login names from classes begin with
\c-". If your name were Wolfgang Amadeus Mozart, your login name would be c-mtwa, following
the recipe of c-(rst letter of last name) (last letter of last name)(rst letter of rst name)(middle
initial). (If you don't have a middle name, your login will only have 3 initials, i.e. c-xxx). If there
is more than one person registered during a semester who would have the same login name (say
c-mtwa), then they are assigned the login names c-mtwa1, c-mtwa2, etc. Your initial password is
the mtwa part of your login name followed by the last four digits of your student ID number, not
your social security number. For example, if Herr Mozart's student ID number was 000001234, his
initial password would be mtwa1234. It would be the same regardless of whether his login name
was c-mtwa or c-mtwa3.
The xterm window: There should be an icon that looks like a little computer. Click it and it
will make a window for typing commands etc.
Logging out: Just as important as logging in is logging out. You do this when you nish work
(or when you leave the room). There is an exit icon to log out.
2 Basic Stu
Opening a Web Browser: In the xterm window, type the command firefox & and hit enter.
Or, there might be an icon at the bottom of your screen that you can click on. Once your browser
is open, go to the lab website:
www.math.utah.edu/ davis/1180index.html
This is where you'll be able to download the labs every week.
Directories: It will be to your advantage to have organized directories (folders). By default,
when you open an xterm window, you are in your "home directory". Type ls and hit enter to see
what is in this directory. You might not have any les at all. To make a directory called lab1,
type mkdir lab1 and hit enter. Now, type ls again and hit enter. You should see a directory
called lab1. To move into that directory, type cd lab1 and hit enter. Now you are in the
directory lab1. Then, you can save everything from this in the lab1 directory. I recommend that
you make a new directory for each lab.
3 Maple
Maple is basically just a super graphing calculator. It can help with a wide variety of problems |
arithmetic, algebra, trig, graphing, calculus, etc. It can also solve many kinds of equations. To
open it, type the command xmaple & in your local window. It will open a new window just like
the netscape & command did. Or, there might also be a Maple icon at the bottom of your screen
that you can click on.
1
Arithmetic in Maple
Try these calculations:
>
>
>
>
5 + 2;
5*2;
5^2;
5 - 2;
# asterisk denotes multiplication
# caret denotes a power (exponentiation)
Every Maple command must end with a semicolon. Otherwise, your command is ignored. Maple
is very nicky about such things. The stu after the \#" is a comment { it will be ignored by
Maple but can be useful to help you remember what you were doing or in communicating with
others.
Use the slash to indicate division, as in
> 5/2;
The result is perhaps not what you would expect: Maple likes to keep things in exact form if
possible. However, if you use decimal numbers (like a good scientist), you get decimal answers:
> 5.0/2.0;
> 2.1^10;
You can use parentheses in the normal way:
> (5.0
- 2.1)/(3.73 + 4.1);
Maple can do huge calculations without batting an electron.
>
>
>
>
>
>
100!;
2^100;
Pi;
evalf(Pi);
evalf(Pi, 100);
exp(1.0);
# 1 x 2 x 3 x .. x 99 x 100
#
#
#
#
stays in exact form
converted to decimal
show 100 decimal places
compute $e^{1.0}$
The evalf function converts things to \oating point" form. In the last example, it converted (typed Pi in Maple) to a precision of 100 digits. Here are a few more arithmetic problems:
> 21229/31993;
> ifactor(12345678987654321);
# factor into primes
Editing in Maple
You can pick up a line by darkening it in with the left mouse button. To paste it, click on the
spot where you want it (with the left mouse button again), and then click the middle button. If
you want to change something in the line, use the mouse to nd the spot you want, and then
delete and add characters where the mouse is.
2
Algebra in Maple
Unlike many calculators, Maple can do algebra. Try the following:
>
>
>
>
m := 3.12; a := 4.6;
m*a;
m := 2;
m*a;
Notice that you assign a value to a variable using the special command \:=" and not just \=".
Maple is also nicky about this.
Maple can solve many algebraic equations. To solve 2x + 5 = 8, type
> solve(2*x+5=8,x);
This tells Maple to solve the given equation for x. To get the answer in decimal form, put in some
decimal points. Make up a quadratic and test Maple's algebra. It is essential to use the little * for
multiplication { Maple does not know what to do with an expression like 2x.
Graphing
Consider the function
f (x) = x(1
To graph it on the interval 0 x 1, type:
x):
> plot(x*(1-x),x=0..1);
Remember to type the little * to indicate multiplication. A graph should appear just below the
command. To change its shape and size, click on it, and then grab the square points on the sides
and corners with the left mouse button. After clicking on it, you can change some of its
properties with the \format" and \style" pull-down menus at the top. We can redo the previous
problem as follows:
> plot(x*(1-x),x=0..1,y=0..1);
Notice that the graph is now \true" or undistorted: the vertical and horizontal scales are the
same. You can set the domain and range to whatever you wish. We can also label the axes and
make a title (with your name, not mine), as follows:
> plot(x*(1-x),x=0..1,y=0..1,labels=["x","f(x)"],title="Liz's first plot");
note: you should always label and title your plots!
Save this graph separately:
{ right click on the plot
{ scroll down to Export As
{ choose Encapsulated PostScript
{ export the graph as plot.eps (by replacing * with plot)
3
{ (make sure you are saving it in the lab1 directory)
{ hit OK
Print this graph separately:
{ bring up an xterm window (you might have to minimize your Maple window)
{ make sure you are in the lab1 directory
{ type ls and hit enter - you should see plot.eps - if not, you're in the wrong directory
{ type lpr -Plcb115 -l plot.eps and hit enter
{ the -Plcb115 tells it which printer to use and the -l tells the printer that you mean it.
{ it will print-out at the printer in LCB 115
{ it should be accompanied by a cover sheet with your login name printed on it.
Multiple plots
Sometimes it is useful to plot several curves at once. To plot the curves
f (x)
g(x)
= x(1 x)
= 4x(1 x)
on a single graph, type:
> plot([x*(1-x),4*x*(1-x)],x=0..1);
You can add a legend to this plot by typing:
> plot([x*(1-x),4*x*(1-x)],x=0..1,legend=["f(x)","g(x)"]);
You can add a title by typing:
> plot([x*(1-x),4*x*(1-x)],x=0..1,legend=["f(x)","g(x)"],title="Multiple Plots");
note: when plotting multiple curves on a single graph, you should always include a legend!
Functions
To get the graphs of f and g above, we typed the formulas straight into plot. A better way is to
dene a function as follows:
> f := x -> x*(1-x);
The little thing that looks like an arrow is typed with a dash followed by a \greater than" sign
(no space between them). This is supposed to represent the function as an operation, eating x
and spitting out x(1 x). Type in
> f(0.5);
Maple returns the correct answer of 0:25.
To plot the graph of a function, type
4
> plot(f(x),x=0..1);
Try typing
> plot(f,x=0..1);
Doesn't look too impressive, does it? A function like f needs to know what it is operating on. Try
typing
> f(z);
The function does its thing to whatever you put inside the parentheses.
To study a family of functions, we can include a parameter, such as
> F := x -> k*x*(1-x);
We can give the variable (or parameter) k any value we want after dening the function.
>
>
>
>
k := 1;
plot(F(x),x=0..1);
k := 3;
plot(F(x),x=0..1);
The plot changes because Maple plugged in the new value of k. If you forgot to give k a value,
Maple would refuse to plot the function. To return k to its status as an undened parameter, type
> k := 'k';
Make sure to use the single quote. To check the value of the parameter k, type
> k;
5
4 Saving and Printing your Maple worksheet
To save your worksheet, go to the File menu at the top left, and click on Save or Save As. Some
odd-looking stu will appear. All you have to do is replace the little * in front of .mws under
Filename with a name like practice and hit OK. If you want to use this le again, you can
open it with the Open option under the File menu. Hitting Save now and then will spare you
from losing everything when you crash Maple, which does happen.
To print, go again to the File menu at the top left. Click on Print. The box for the option
Output to File should be darkened in. In the box to the right, you can type in a name of the
le (although there should already be a default name ending in .ps), such as practice.ps. If you
like the name, click on Print. This saves a le in P ostscript form, the language spoken by
printers. To print your le, go to the local window and type the command
lpr -Plcb115 -l practice.ps
and hit return. The -Plcb115 tells it which printer to use and the -l tells the printer that you
mean it. Your print-out will appear at the printer, with a cover sheet with your login name.
5 Finishing up
Remember to log out!
Remember to change your password if you haven't already. Type \passwd" in your local
window and follow instructions. Don't choose an obvious password.
Sources of information:
1. Your instructor and the lab assistants
2. Your classmates, the person at the next workstation. Don't be afraid to ask questions.
Every expert was once a beginner.
A nal word: In the beginning computing is frustrating because we are used to dealing with
people, who are intelligent and cn undrstond whot u meen evn if it isn't quite right from a
literal point of view. You will soon get past this stage as the right moves become automatic.
Eventually computers will be smarter and better designed, and this will make life easier for
all of us.
6
Download