{VERSION 6 0 "IBM INTEL NT" "6.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 1 12 255 0 0 1 2 1 2 2 1 2 0 0 0 1 }{CSTYLE "Text" -1 207 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 256 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 257 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 258 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 259 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 260 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 261 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 262 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" 207 263 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 264 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 265 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 266 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 267 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 268 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 269 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 270 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 271 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 272 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 273 "" 0 1 0 0 0 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0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 315 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 316 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 317 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" 207 318 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" 207 319 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 320 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 321 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 322 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{PSTYLE "Normal " -1 0 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 2 0 2 0 2 2 0 1 }} {SECT 0 {EXCHG {PARA 0 "" 0 "" {TEXT 256 47 "Working with polynomails \+ and other expressions." }{TEXT -1 53 "\nMove the cursor to a command a nd run it by pressing " }{TEXT 262 5 "Enter" }{TEXT -1 276 ". You will be automatically sent to the next command (or rather, to the next gro up, see below). You can also go up and down using arrows on your keybo ard and run groups, but be careful and try not to click on groups that use results from other groups that you did not run yet." }{TEXT 207 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 55 "The simplest task it to as k Maple for some calculation." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "2^3/5+4*sqrt(5);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 248 "Every \+ command must end with a semi-colon or a colon. The colon means that th e command will be executed, but the output will not be shown.\nMaple k nows the basic algebrais operations of course. Multiplication must alw ays be indicated by the asterisk " }{TEXT 273 1 "*" }{TEXT -1 124 ". L eaving it out is a popular mistake and the usual suspect when our code is acting up. A power is done using the character " }{TEXT 272 1 "^" }{TEXT -1 61 ", say, 13^2=196. We also learned how to indicate square \+ root." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 268 "Before we look at other functions, we comment on the answer. Note that the square root was no t evaluated. Maple is very good at calculating with symbols, and if po ssible, it keeps precise expressions. It has no problem doing simpler \+ calculations with symbolic objects." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "sqrt(40)/2+sqrt(8)*sqrt(2);" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 166 "However, sometimes we want to see an actual number. Th ere are two basic ways to achieve that. One is to include some real nu mber, which is indicated by a decimal dot." }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 28 "sqrt(40.)/2+sqrt(8)*sqrt(2);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 112 "The other possibility is to use a special command t hat transforms a symbolic numerical expression into a number." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "evalf(sqrt(40)/2+sqrt(8)*sqr t(2));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 107 "We can specify how pre cise the result should be as a second argument. By the way, the defaul t is 10 digits." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "evalf(sq rt(40)/2+sqrt(8)*sqrt(2),130);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 11 "By the way," }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "evalf(Pi,13 0);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 45 "This command can also hand le complex numbers." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "eval f(sin(1)+2*I);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 67 "Now back to fun ctions. Maple knowsclassical functions for instance " }{TEXT 274 6 "si n(x)" }{TEXT -1 2 ", " }{TEXT 275 6 "cos(x)" }{TEXT -1 2 ", " }{TEXT 276 9 "arctan(x)" }{TEXT -1 2 ", " }{TEXT 277 5 "ln(x)" }{TEXT -1 2 ", " }{TEXT 278 10 "log[10](x)" }{TEXT -1 2 ", " }{TEXT 279 9 "log[2](x) " }{TEXT -1 2 ", " }{TEXT 280 7 "sqrt(x)" }{TEXT -1 2 ", " }{TEXT 281 10 "root[3](x)" }{TEXT -1 4 " or " }{TEXT 282 9 "root(x,3)" }{TEXT -1 27 " and such. BUT if we write " }{TEXT 286 3 "e^x" }{TEXT -1 56 ", th en Maple iterprets it as some (unknown?) expression " }{TEXT 288 1 "e " }{TEXT -1 17 " raised to power " }{TEXT 287 1 "x" }{TEXT -1 41 ". Th e exponential must always be done as " }{TEXT 283 6 "exp(x)" }{TEXT -1 29 ", so for instance the number " }{TEXT 284 1 "e" }{TEXT -1 25 " \+ can be obtained through " }{TEXT 285 6 "exp(1)" }{TEXT -1 34 ". This i s another popular mistake." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 132 "So metimes it is not easy to figure out why some calculation misbehaves. \+ One mischievous operation is the root. One would think that " }{TEXT 313 10 "(-8)^(1/3)" }{TEXT -1 4 " or " }{TEXT 312 10 "root(-8,3)" } {TEXT -1 143 " is -2. Unfortunately, these operations provide so-calle d principal root in complex setting. We cannot tell when we see a symb olic output, but " }{TEXT 314 5 "evalf" }{TEXT -1 27 " makes the situa tion clear." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "(-8)^(1/3); \nevalf((-8)^(1/3));\nroot(-8,3);\nevalf(root(-8,3));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 62 "If we want the \"normal\"root, we have to use a special command." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 " surd(-8.,3);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 242 "By now the reade r should feel comfortable with basic calculations. Perhaps (s)he woudl like to practice a bit now. But where? This is a familiar situation t hat we are somewhere within a worksheet, trying to do some work, and r un out of room. " }{TEXT 289 6 "Ctrl-K" }{TEXT -1 64 " creates a new e mpty group above the one where you are now, and " }{TEXT 290 6 "Ctrl-J " }{TEXT -1 58 " creates it below. Talking about empty groups, we can \+ hit " }{TEXT 291 6 "Ctrl-T" }{TEXT -1 61 " and the empty group changes into a text group like this one." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 225 "Talking about familiarity with Maple, we recommend that reader tr ies the follwing three experiments. First: In the menu, click on help, then choose Topic Search and ask for \"root\". The second experiment: Run the next command." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "? \+ root;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 144 "The third experiment: G o several groups back and use your mouse to highlight \"root\" in \"ev alf(root(-8,3))\", then hit F2 or F1 in older versions." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 42 "Now we move to something more interesting." }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 154 "e1:=(x-1)*(x+1)*(x+13);\n# We defined an \" expession\" and stored it in a named variable.\n# By the way, the pris on mark is used to start lines with comments." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 44 "Assignment is done using the twin character " }{TEXT 315 2 ":=" }{TEXT -1 185 ".\nWe can name a variable in almost any way \+ we want using letters (the case matters) and numerals. We have to stic k clear of reserved names. We have already encountered the complex uni t " }{TEXT 304 1 "I" }{TEXT -1 26 ", another popular name is " }{TEXT 303 2 "Pi" }{TEXT -1 4 " or " }{TEXT 322 1 "D" }{TEXT -1 207 " used in differentiation (beware, forbidden!). Maple also knows Greek letters. An interesting type of reserved variables is registers that store sys tem settings for Maple. One is worth knowing, the register " }{TEXT 305 6 "Digits" }{TEXT -1 210 " tells Maple how many digits should be k ept when doing calculations.\nThis freedom when creating names for var iables explains why Maple demands that we use asterisk to show multipl ication; for instance it sees " }{TEXT 306 2 "2x" }{TEXT -1 27 " as a variable called \"2x\"." }}}{EXCHG }{EXCHG {PARA 0 "" 0 "" {TEXT -1 58 "We find the contents of a variable we simply run its name." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 3 "e1;" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 32 "We can also ask about its value." }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 10 "value(e1);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 81 "If we want to substitute into an expression, the natural way is to simply assign " }{TEXT 316 1 "x" }{TEXT -1 12 " some value." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "x:=5;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 15 "The expression " }{TEXT 266 2 "e1" }{TEXT -1 19 " sh ould now be 432." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 3 "e1;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 109 "However, this approach has severa l disadvantages, for instance we lost the access to the original expre ssion " }{TEXT 267 2 "e1" }{TEXT -1 108 " and also the variable x is n o longer available. To see what this means we try to define another ex pression." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "e2:=x+8;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 418 "This is not what we really wanted . Before we look at a non-destructive way to subtitute into an express ion, we will address the problem of fixing the situation when we assig n some variable a value by mistake. We can run the command \"restart\" that resets everything, but that is a nuclear option. It is possible \+ to return a variable its original meaning locally by quoting it using \+ apostrophes, that is, we would write " }{TEXT 320 9 "e2:='x'+8" } {TEXT -1 151 ". However, this is not something one wants to do often. \+ Usually the best option is to untie the variable from its content by a ssigning it its own name." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "x:='x';" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 10 "Let's see." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "e1;\ne2:=x+8;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 212 "We can run more commands in one group, t hen we see more outputs. The code reads better if every command has it s own line. If we want to go to the next line within one group without running it, we use Shift-Enter." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 88 "Now for the b etter substitution. We san substitute into an expression using the com mand " }{TEXT 261 4 "eval" }{TEXT -1 43 ". The order of arguments is t o where, what." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "eval(e1,x =5);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 158 "This command is quite sm art, it can also handle substituting expressions into expressions, and it the result can be reasonably simplified, then it will do it." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "eval(e1,x=2*y+1);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 72 "There is a competitor in the subst itution business. Beware, the command " }{TEXT 260 4 "subs" }{TEXT -1 54 " expects arguments in the opposite order (what-where)." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "subs(x=5,e1);" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 41 "It can also substitute other expressions." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "subs(x=y^2,e1);\nsubs(x=x+1, e1);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 80 "The two commands work abo ut the same when it comes to substituting numbers, but " }{TEXT 268 4 "eval" }{TEXT -1 93 " could be a bit more practical due to its willing ness to simplify. Compare the following run." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "eval(cos(x),x=0);\nsubs(x=0,cos(x));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 139 "There is a substantial difference betwee n these two commands when it comes to higher level usage, but we do no t have to worry about it now." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 82 " Now we will show some examples of Maple's great skill in manipulating \+ expressions." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "expand(e1); " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 84 "And now we ask for factorizat ion, let's see whether Maple will find its way back to " }{TEXT 269 2 "e1" }{TEXT -1 1 "." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "fact or(%);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 4 "The " }{TEXT 292 1 "%" } {TEXT -1 53 " sign refers to the previous result, we can also use " } {TEXT 293 2 "%%" }{TEXT -1 38 " to refer to the next last result and \+ " }{TEXT 294 3 "%%%" }{TEXT -1 221 " to go back by three. Beware, the \+ word previous means the last work done by the processor, not what you \+ see on the above line. If we move the cursor down, run some groupthere , then come back here and run this group, then " }{TEXT 295 1 "%" } {TEXT -1 154 " will stand for that output down there. So these referen ces can be very risky, it is safer to store intermediate results in va riables (expressions), say, " }{TEXT 296 16 "rslt:=expand(e1)" }{TEXT -1 10 " and then " }{TEXT 297 12 "factor(rslt)" }{TEXT -1 238 ". There is another danger, when the output consists of more lines, then diffe rent versions of Maple treat it differently. Some take it as one compo sed answer, some take it as several answers. But in simple situations, the back references " }{TEXT 299 1 "%" }{TEXT -1 2 ", " }{TEXT 298 2 "%%" }{TEXT -1 31 ", etc. can be quite convenient." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 41 "Now we will find roots of the polynomial " } {TEXT 317 2 "e1" }{TEXT -1 1 "." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "roots(e1);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 124 "Maple foun d them, it even added information about multiplicity. The format of th is output is a so-called \"list\", denoted by " }}{PARA 0 "" 0 "" {TEXT 207 168 "[...]. We actually see three lists of the form [root,mu ltiplicity] that create another list. How to we get to those numbers? \+ Using coordinates, but first we store them." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "rts:=roots(e1);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "rts[2];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 128 "Yes, \+ the second component of the list is this pair. Now we ask for the firs t component of this pair and we have the second root." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "rts[2][1];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 207 90 "Let's see whether Maple can handle multiplicities wel l, we will give it x(x-13)^2 to solve" }{TEXT -1 1 "." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "roots(x^3-26*x^2+169*x);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT 207 138 "Yes, it did recognize that the 1 3 is a double root. However, for solving general equations there is an other command, we will see it later." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 74 "One of the strong sides of Maple is its ability to manipulate e xpressions." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "e3:=(x+1)*(x -1)*(x^2+13);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "simplify(e 3);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 160 "We never know what the ou tcome of \"simplification\" will be, as \"simple expression\" is a hig hly subjective notion. Maple has a very specific way of judging this. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "expand(e3);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "simplify(%);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 64 "After multiplying out, Maple changes its mind on wha t simple is." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "factor(%); " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 30 "But it can go back to factors ." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 257 18 "Solving equation s." }{TEXT -1 142 "\nThere are two major approaches, symbolic or numer ical. We start with the symbolic (or algebraic) approach and return to the first expression." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "s olve(e1=0);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 270 "As we can see, so lve expects to work with general expressions and therefore it does not identify multiplicities.\nIt is enough to write solve(e1), then Maple fils in \"=0\" automatically. Solve either manages to solve the equat ion symbolically, or it does not say anything." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 342 "The output here is a \"sequence\" of objects. The c ontents of a list is a sequence, and conversely, when we enclose a seq uence is square brackets [ ], then it becomes a list. It is thus easy \+ to pass from one to another as needed. We can access individual compon ents in a sequence just like with lists. Say, the third one is extract ed like this." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 1 "%" }{TEXT -1 0 "" }{MPLTEXT 1 0 4 "[3];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "solve(x^3-2*x+1=0);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 47 "What numbers are these? We can use the command " }{TEXT 300 5 "evalf" } {TEXT -1 20 " introduced earlier." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "evalf(%);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 14 "Note that the " }{TEXT 270 5 "evalf" }{TEXT -1 116 " command acted on all \+ three components in out sequence. producing a sequence of answers. Man y commands can do that. " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 235 "If t here is just unknown in the equation, Maple chooses it automatically. \+ However, when there more symbols, then we have to specify which one sh ould be isolated from the equation, as Maple considers all letters to \+ be equally important." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "so lve(a*x+b=0,x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 61 "As you can see , Maple is really good at working with symbols." }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 17 "solve(a*x+b=0,b);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 118 "When we accidentally assign a value to our working varia ble, we find out when we attempt to use them it as a variable." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "x:=13:\nsolve(a*x+b=0,x);" } }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 250 "This is actually a fairly commo n mistake even for an experienced Mapler, so it is one thing to think \+ of when our code refuses to work the way we expect. Note the error mes sage, you are likely to see something like that again. We'd better rel ease our " }{TEXT 271 1 "x" }{TEXT -1 12 " to be sure." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "x:='x';" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 84 "As we said, when picking names for variables, you can let your imagination run free." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 62 "solve(dontknow^2-(something+2)*dontknow+2*something,dontknow);" }} }{EXCHG {PARA 0 "" 0 "" {TEXT -1 98 "Now we will try something more co mplicated, namely an equation that cannot be solved symbolically." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "solve(exp(x)=13*x);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 65 "\"LambertW(x)\" is a symblic name \+ for the solution of the equation " }{TEXT 307 6 "ye^y=x" }{TEXT -1 92 " which cannot be solved algebraically, byt the solution exists (infin itely many in fact). Ma" }{TEXT 302 0 "" }{TEXT -1 133 "ple therefore \+ introduced a name that refers to tis solution, and uses it to express \+ solutions of other equations. But how much is it?" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 9 "evalf(%);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 165 "This is a numerical approximation of a symbolic expression. In that case it might be better to directly apply numerical methods to o ur equation. This will come soon." }}{PARA 0 "" 0 "" {TEXT -1 68 "Sinc e we will be returning to this equation, we will give it a name." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "eqn:=exp(x)=13*x;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 27 "Now you see why Maple uses " } {TEXT 301 2 ":=" }{TEXT -1 136 " for assignment, the equality sign the n stays avaiable and we can also store equations.\nNow we will store t he solutions as real numbers." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "soleqn:=evalf(solve(eqn));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 207 112 "Let's check whether these numbers really are a solution. Substitu tion into an equation has to be done carefully." }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 19 "subs(x=soleqn,eqn);" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 72 "What happened? We attempted to substitute into an expre ssion a sequence " }{TEXT 308 6 "soleqn" }{TEXT -1 104 " with two entr ies, which does not make sense. We can also try the other command, per haps more practical." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "eva l(eqn,x=soleqn);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 56 "So this one s ent us to *** (which by the way shows that " }{TEXT 309 4 "subs" } {TEXT -1 18 " is more capable)." }}{PARA 0 "" 0 "" {TEXT -1 157 "Tak t enhle nas dokonce rovnou poslal do haje (coz mimo jine ukazuje, ze sub s umi veci navic).\nWe have to substitute individual entries, which is easily done." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "eval(eqn,x =soleqn[1]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "eval(eqn,x= soleqn[2]);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 22 "By the way, how wo uld " }{TEXT 310 4 "subs" }{TEXT -1 13 " handle this?" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "subs(x=soleqn[1],eqn);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "evalf(%); \n# So how much is it? " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 27 "We had to do an extra step." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 214 "However, such comparison of ex pressions is risky, because we see just a certain number of digits, so we do not know whether there is a difference further out. Is is bette r to check on the difference of LHS and RHS." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "eval(exp(x)-13*x,x=soleqn[1]);\neval(exp(x)-13*x ,x=soleqn[2]);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 170 "The second roo t did not yield zero, and now it is not clear whether this is just a r ounding error, or a real problem with that root. We will return to thi s problem below." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 111 "When we cannot solve an equation \+ symbolically, we approach it numerically. There is a special command f or that." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "fsolve(eqn);" } }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 26 "Ted zkusime jinou rovnici." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "ls:=2*sin(x)-cos(x)-x;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "solve(ls);\n# So we are solv ing ls=0." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 87 "Maple is silent, it \+ cannot solve this symbolically. We will try the numerical approach." } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "fsolve(ls=0);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "eval(ls,x=%);\n# Check." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 12 "The command " }{TEXT 311 6 "fsolve" } {TEXT -1 126 " can provide more solutions for polynomials, but because it looks for them numerically, it cannot provide them in a nice form. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "fsolve(x^3-2*x+1=0);" } }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 258 "However, checking on solutions \+ in computers is tricky. First, calculations are accompanied by numeric al errors, so a true root may not give zero. Second, computers cannot \+ store very small numbers and replace them with zeros, so a faulty \"ro ot\" may give zero." }}}{EXCHG {PARA 0 "" 0 "" {TEXT 207 51 "We will t ry to find the intersection of two curves." }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 27 "a:=fsolve(sinh(x)=cosh(x));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 207 62 "Let's check. We substitute this \"a\" into the diff erence using " }{TEXT 319 4 "eval" }{TEXT 207 9 " and let " }{TEXT 318 5 "evalf" }{TEXT 207 51 " act on it right away to see the anwer as a number." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "eval(cosh(x)- sinh(x),x=a);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 207 118 "It seems that \+ this checks out, we should be happy. However, what happens if we incre ase the precision of calculations?" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "Digits:=100;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "a100:=fsolve(sinh(x)=cosh(x));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 42 "This is interesting, a different solution." }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 12 "Digits:=200;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "a200:=fsolve(sinh(x)=cosh(x));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 24 "Curiouser and curiouser." }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 12 "Digits:=500;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "a500:=fsolve(sinh(x)=cosh(x));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 207 142 "Maple gave up. We have many candidates for solution. In fact there is none, the two curves do not intersect. Numerical calcul ations are risky." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "Digits :=10;\n# we'd better reset the precision to the default." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 69 "We did quite a lot of work, it may be a g ood idea to clean the slate." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 22 "Maple can also handle " }{TEXT 258 6 "syt ems" }{TEXT -1 26 ", especially simpler ones." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 42 "e1:=x^2-3*y+z=2;e2:=x-y+z=2;e3:=2*x+y-z=4;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "solve(\{e1,e2,e3\},\{x,y,z\} );" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 108 "We can interfere with the \+ process, for instance we may want to simplify some equation using othe r equations." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 73 "simplify(e1 ,\{e2,e3\});\n# Equation e1 should be simplified using e2 and e3." }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 18 "Or some other way." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 72 "simplify(\{e1,e2\},\{e3\});\n# Equa tions e1,e2 should be simplified using e3." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 99 "We obtained two equations with two unknowns. We can even \+ choose which unknown should be eliminated." }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 27 "simplify(\{e1,e2\},\{e3\},\{z\});" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 32 "Or we work with fewer equations." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 76 "simplify(e1,\{e2\},\{x\});\n# We re move x from equation e1 using the equation e2." }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 43 "simplify(e1,\{e2\},\{y\});\n# Now we kick out \+ y." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 56 "We will look at a system wi th infinitely many solutions." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "solve(\{x+y+z=0,2*x-z=2\},\{x,y,z\});" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 21 "Maple decided to use " }{TEXT 321 1 "z" }{TEXT -1 53 " \+ as a parametr for expressing the other two unknowns." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 132 "Trick: Consider two unknowns determined by two equations, we want to substitute the solution to a function that uses these unknowns." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "ee1:=x+ y=3;ee2:=2*x-y=0;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "simpli fy(x^2-e^y,\{ee1,ee2\});" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 133 "Of c ourse, this will only work with friendly equations that Maple can hand le syymbolically. Then it it does not even mind parameters." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "simplify(x^2-e^y,\{x+y=a,2*x -y=b\});" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 " " 0 "" {TEXT 259 28 "Bonus: The Newtonova method." }{TEXT -1 105 "\nWe will try to create an implementation of the Newton method. We use it \+ to find the third root of eight." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "fnct:=x^3-8;\n# We submit the expression." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 78 "dfnct:=diff(fnct,x);\n# We find its derivative (see the appropriate worksheet)." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "xnewt:=1;\n# The initial guess." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 102 "xnewt:=xnewt-eval(fnct,x=xnewt)/ev al(dfnct,x=xnewt);\n# We find the new xnewt using the Newton formula. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 183 "evalf(%,20);\n# How do es it actually look like?\n# The second parameter asks for the result \+ with precision 20 digits.\n# However, the precision of calculations is still the original one." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 " " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 86 "Now all you have to do is to \+ go back to the line with Newton, the one that starts with" }{TEXT 207 1 " " }{TEXT 263 16 "xnewt:=xnewt-..." }{TEXT 207 266 " and run it, th en run the one under it and you have the second iteration. Then you re turn up, run the two groups and you get the third iteration etc., as l ong as you want. Note how Maple tries to work with precise numbers and gargantuan fractions appear as a result." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 499 "The numbers converge nicely to 2. We will try to shorten the code so that it can be used effectively, we will also include a c ounter of iterations. Since huge franctions slow down calculations, we will convert everything to floating point right away. Then the result s will be less precise, but this is how calculations are done in real \+ life applications (they do not have any choice). To be on the safe sid e we will increase the precision. We will also show how to add a simpl e legend to the output." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 38 "Instru ctions: Put some expression for " }{TEXT 264 4 "fnct" }{TEXT -1 33 ", \+ then fill in the initial value " }{TEXT 265 7 "xnewt:=" }{TEXT -1 126 " and run this group. Then just run the iterative row over and over ag ain (you can return to it by hitting the up-arrow twice)." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "fnct:= exp(x)-13*x;\ndfnct:=diff(fn ct,x):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "xnewt:=1;\nn:=0: \nDigits:=20:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 84 "n:=n+1:xne wt:=evalf(xnewt-eval(fnct,x=xnewt)/eval(dfnct,x=xnewt)):\n'n'=n,'xn'=x newt;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "Digits:=10:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}} {MARK "13 0 0" 14 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }