# Introduction to Maple # =============== # # To start Maple (in the X-terminal lab after logging in), enter the # following command in a terminal window: # xmaple& # # An xmaple window should appear. # The ">" prompt indicates that Maple is ready for your command. # > 2+3; 5 # Note the ";", which is necessary to end a command. After the ";" you # should press the Return key which is above the right Shift (not the # same as the Enter key on the numeric keypad). # (On a Mac or NeXT computer, you need to press Enter, not Return. # On most other computers, Enter and Return are the same) # # Maple prints the result and gives you another prompt. # > 2 + 4: # # This time I used ":" instead of ";". This tells Maple to compute the # result, but not print it. Usually we'll use ";" since there's no reason # not to see the result. # # Another difference between this and the last example is that I put in # spaces on either side of the "+". These spaces are ignored by Maple. # > 2+3*4; 14 # The multiplication sign in Maple is the asterisk *. The division sign # is /. For powers we use ^. # # Maple uses the standard algebraic precedence rules, so 2+3*4 was # interpreted as 2+(3*4), not (2+3)*4. # > 2^1000; 1071508607186267320948425049060001810561404811705533607443750388370351051124936\ 1224931983788156958581275946729175531468251871452856923140435984577574698574803\ 9345677748242309854210746050623711418779541821530464749835819412673987675591655\ 43946077062914571196477686542167660429831652624386837205668069376 # That's something your calculator probably can't do. Maple can # handle very large integers. # # The "\" at the end of a line means that the number is continued to the # next line. # > 21/39; 7/13 # It writes fractions as fractions (automatically reducing them to lowest # terms), without resorting to decimal approximations. If you do want # to see this as a decimal, you can use the "evalf" command. As with # almost every Maple command, the input to "evalf" is enclosed in # parentheses. > evalf(7/13); .5384615385 # The default (what Maple does unless otherwise specified) is to show # 10 significant digits. This can be changed, using a variable called # "Digits". Let's see this number to 25 digits instead of 10. # > Digits:= 25: > evalf(7/13); .5384615384615384615384615 # - Maple is case-sensitive. "Digits" is not the same as "digits" or # "DIGITS". Those wouldn't affect the number of digits Maple prints. # - ":=" is the assignment sign in Maple. It means "assign the value on # the right to the variable on the left". This is different from "=" which # makes an equation. # - Once "Digits" has been set, Maple uses this setting every time it # computes a decimal result until you change "Digits" again. If you # want to change the number of digits for one "evalf" command only, # you can specify this as a second input to "evalf". The inputs are # separated by a comma. # > evalf(7/13, 40); # .5384615384615384615384615384615384615385 # - In the professional editions of Maple (e.g. the one in the X lab) # Digits can be as large as you want (until you run out of memory). In # student editions, the maximum is 100. # > Digits:= 10: > x^2 - 3*x - 4; # 2 x - 3 x - 4 # The "x" here is a symbolic variable. Maple can do algebra as well as # arithmetic. Note that the output looks like ordinary typeset # mathematics, with exponents as superscripts and omitting the * for # multiplication. # # Often we'll want to have Maple remember something for later use. # This will save us from doing things over and over again. We can # store an expression in a variable. # > f:= x^2 - 3*x - 4; 2 f := x - 3 x - 4 # I really didn't need to type the "x^2 - 3*x - 4" again. The very useful # symbol " stands for "the result of the last command". So I could have # said # > f:= "; 2 f := x - 3 x - 4 # There are also "" for the second-last and """ for the third-last result # (but that's as far back as it goes). # # Actually I didn't type "x^2 - 3*x - 4" again. XWindows, just like # Macintosh and Windows, has a copy-and-paste facility. You select # some text by dragging the mouse pointer across it, and press the # middle mouse button to paste it. # # Let's solve an equation. # > solve(f=0,x); 4, -1 # This command told Maple to solve the equation x^2 - 3*x - 4 = 0 # (since the value of the variable f is x^2 - 3*x - 4) for x. Since there's # only one variable in the equation, we didn't really need to specify the # "x": we could have used "solve(f=0)". In fact we could have used # "solve(f)", because "solve" automatically interprets an expression # that is not an equation as "expression = 0". There are two solutions, # x = 4 and x = -1, and Maple gives us both, separated by a comma. # "solve" will return all the solutions of a polynomial equation. # > solve(x^4 - x^2*y + y^2/4 = 0, x); 1/2 1/2 1/2 1/2 1/2 1/2 1/2 1/2 1/2 2 y , - 1/2 2 y , 1/2 2 y , - 1/2 2 y # We needed the "x" in this one because there were two possible # variables, x and y. Note that the double roots are given twice. # > solve(x^3 - x - 1, x); 1/3 1 1/3 1 1/2 / 1/3 1 \ %1 + -------, - 1/2 %1 - ------- + 1/2 I 3 |%1 - -------|, 1/3 1/3 | 1/3| 3 %1 6 %1 \ 3 %1 / 1/3 1 1/2 / 1/3 1 \ - 1/2 %1 - ------- - 1/2 I 3 |%1 - -------| 1/3 | 1/3| 6 %1 \ 3 %1 / 1/2 %1 := 1/2 + 1/18 69 # There are three solutions here (the commas are sometimes hard to # spot). "I" is Maple's notation for the square root of -1. Maple often # writes complicated expressions by introducing variables %1, %2 etc. # which stand for parts of the expression that occur in more than one # place. Let's save this result. # > s:= ": # You can pick out individual solutions as s[1], s[2], and s[3]. # > s[2]; 1/3 1 1/2 / 1/3 1 \ - 1/2 %1 - ------- + 1/2 I 3 |%1 - -------| 1/3 | 1/3| 6 %1 \ 3 %1 / 1/2 %1 := 1/2 + 1/18 69 > evalf("); - .6623589787 + .5622795120 I # Here's one that Maple won't produce a "closed-form" solution for: # > solve(x^5 - x^3 + 2*x + 1, x); 5 3 RootOf(_Z - _Z + 2 _Z + 1) # There's a good reason for that: in general, polynomials of degree 5 # and higher can't be solved in terms of radicals. What about # non-polynomial equations? # > solve(sin(x) = 1/2, x); 1/6 Pi # Yes, that's one solution, but it's certainly not the only one. Let's try # some harder equations. # > solve(sin(x)=1-x, x); > solve(exp(x)=y-x, x); - W(exp(y)) + y # Maple had no luck with the first one. Rather surprisingly, it did find a # solution for the second. # Note the use of "exp" for the exponential function. # Maple's output shows it almost as if it were e^x, but actually there is # a subtle difference if you see them together. > e^x , exp(x); x e , exp(x) # The "e" of e^x is in an italic font that Maple uses for variables, while # the "e" of exp(x) is in a Roman font that is used for functions. The # letter "e" is just an ordinary variable as far as Maple is concerned. # The constant 2.71828... is E. (Actually, in the next release of Maple, # E won't be anything special either, so it's best to use exp.) # > evalf(e), evalf(E); e, 2.718281828 # Now back to W. What is it? This may be a good place to introduce # Maple's help facility. To find out about any Maple command or # function, just ask: # > ?W # No ";" is needed for help. The help page comes up in its own window # on the X terminal. # # FUNCTION: W - Lambert's W function # # CALLING SEQUENCE: # W(x) # W(k, x) # # PARAMETERS: # x - an expression # k - an expression, understood to be an integer # # SYNOPSIS: # - Lambert's W function satisfies # # W(x) * exp(W(x)) = x . # # - As the equation y exp(y) = x has an infinite number of solutions y # for each (non-0) value of x, W has an infinite number of branches. # Exactly one of these branches is analytic at 0. In Maple this branch is # referred to as the principal branch of W, and is denoted by W(x). The # other branches all have a branch point at 0, and these branches are # denoted in Maple by W(k,x), where k is any non-zero integer. (The # principal branch can also be referred to as W(0,x)). # etc.... # # Well, a lot of this might not make much sense to you until Math 301, # but when you want it, it's there. The most useful parts of the help # page are often the "calling sequence" and "parameters", which tell # you the number and types of inputs to use for a command or function, # the "examples" section at the end which often shows it being used in # just the way you want to use it, and the "see also" right at the end (if # the command you asked about is not quite what you need, the one # you do need may well be mentioned there). # # Anyway, W is a certain function that Maple knows about, that can be # used to solve many equations involving exponentials or logarithms. # # But what about those equations that "solve" can't handle? They will # be taken care # of by "fsolve" (in the next lesson...)