Maple: An Introduction David F Griths Department of Mathematics and Computer Science University of Dundee Dundee DD1 4HN Email: [email protected] CONTENTS 2 1 What is Maple? 2 2 Numbers etc. 4 3 Maple Expressions 6 4 Maple Quiz #1 7 5 Assignments = 7 Contents & := 6 Built-in Functions 10 7 Algebraic Manipulation 11 8 Maple Quiz #2 13 9 Dierentiation 14 10 Integration 15 11 Maple Quiz #3 16 12 Plotting with Maple 16 13 Substitution 19 14 Dierential Equations 20 15 Quiz 4 23 16 Integration|2 23 17 Functions 25 18 Linear Algebra 26 19 Calculus of Several Variables 30 20 Mappings in 2 Variables 32 21 Transforming Derivatives 34 dfg , January 5, 1996 1: INTRODUCTION 1 What is Maple? 3 > J = value(J); Z 1 4 e( ,2 x ) x sin( x ) dx = 25 0 Maple is a computer program that can carry out symbolic, numerical, and graphical computations. It can relieve you of the burden of doing computa- Evaluate the sum tions by hand. Maple covers topics from calculus, > linear algebra, dierential equations, geometry, S := Sum((-1)^n/n!,1 n=1..infinity); n X statistics and many others. S := ( ,n1! ) n=1 SYMBOLICS Maple's symbolic routines allow you > S = value(S); to use variables such as "x", "y", "x3" or "Temp" 1 ( ,1 )n X without numerical values and perform normal al= e( ,1 ) , 1 n ! gebraic manipulation on complicated expressions n=1 involving these variables. Constants may be given in exact form (e.g., 1/3 as opposed to 0.333...) so that Maple provides exact answers. The exam- NUMERICS Some problems may have exact anples that follow are meant to give a avour of swers that are too cumbersome to be useful. For what Maple can do. We shall cover the meaning example, evaluate the sum > S := Sum((-1)^n/n!, n=1..20); of the commands later. 20 n X S := ( ,n1! ) Factorisation n=1 > x^2-3*x+2=factor(x^2-3*x+2); x2 , 3 x + 2 = ( x , 1 ) ( x , 2 ) Conversion to partial fractions: > f := (x+1)/(x^3+x^2-6*x); > f = convert(f,parfrac,x); f := x3 +xx+2 ,1 6 x x+1 =, 1 1 , 2 1 + 3 1 3 x + x2 , 6 x 6 x 15 x + 3 10 x , 2 We get Maple to forget the value of f using > f := 'f'; f := f > S = value(S); 20 n X ( ,1 ) = ,7358312808534631 n! 11640679464960000 n=1 We can evaluate this in decimals using the "evalf" command - short for "evaluate as a oating point number": > S = evalf(S); ( ,1 )n = ,:6321205588 n! n=1 20 X The basic precision of numerical computations is 10 signicant gures, we may change this by adding an extra argument to "evalf" giving it the Example: Solve the equations (labelled "e1" and number of signicant gures that we want: "e2") for x and y: > S = evalf(S,3); > e1:= a*x+5*y=1; 20 X ( ,1 )n = ,:632 e1 := a x + 5 y = 1 n! n=1 > > e2:=2*x-3*y=3; e2 := 2 x , 3 y = 3 solve({e1,e2}, {x,y}); y = , ,102 ++ 33aa ; x = 18 10 +1 3 a Evaluate the integral > J := Int(exp(-2*x)*x*sin(x), x=0..infinity); J := 1 Z 0 e( ,2 x ) x sin( x ) dx > S = evalf(S,20); n ( ,1 ) = ,:63212055882855767839 n! n=1 Maple can work to "innite precision" in principle, though the more gures requested, the longer the calculation will take. 20 X Other problems cannot be solved exactly for example, nd the real roots of the polynomial > p:=x^5-x^2+1; p := x5 , x2 + 1 1: INTRODUCTION We can try to do this with the "solve" command, which, in this case solves the equation "p=0" for "x": > 4 07816406286208998628034825342117n 0679821480865132823066470938 solve(p,x); RootOf( Z 5 , Z 2 + 1 ) GRAPHICS Maple provides many ways of drawing curves and surfaces in two and three dimensions. More examples are given in a later chapter This does not give an answer so we resort to nu- of this tutorial, "Plotting with Maple". merical evaluation of the roots: > fsolve(p,x); Recall the polynomial we dened earlier; ,:8087306005 > p; which gives one real root. x5 , x2 + 1 We may plot this curve in the rectangle,5 < The remaining roots are presumed to be complex x < 5; ,5 < y < 5 with numbers - we can also nd these by prompting > plot(p,x=-5..5,y=-5..5); Maple: > rts:=fsolve(p,x,complex); rts := ,:8087306005; ,:4649122016 , 1:071473840 I; ,:4649122016 + 1:071473840 I; :8692775018 , :3882694066 I; :8692775018 + :3882694066 I 4 y 2 -4 -2 0 0 2 4 x -2 -4 The result of the computation has been labelled "rts", so that we can identify the fourth root, for This graph seems to verify the earlier conclusion instance, by that p had only one real root. To "kill" the > rts[4]; graphics window that has appeared, point the :8692775018 , :3882694066 I The value of the variable named roots is a "se- mouse into it and type "q" (without the quotation marks). quence" of complex numbers. Usually, the numerical answer to a problem is not exact (since it will be given only to a certain number of signicant gures) - we get an approximate answer. Another way of doing this is to simply introduce a decimal number into the expression we wish Maple compute. Evaluate the cube root of 5: > 5^(1/3)= 5.0^(1/3); 1=3 5 = 1:709975947 Evaluate Pi to 25 gures > Pi=evalf(Pi, 25); = 3:141592653589793238462643 Evaluate Pi to 125 gures IMPORTANT When you type in any Maple statement, expression, or command, you must make sure that you end it with either a SEMICOLON or a COLON. Until you do so, Maple does not know that you want to calculate what you've entered, and it just patiently waits for you to complete your command (no matter how many lines you enter). The semicolon is the standard Maple command terminator. It tells Maple to calculate the previous input and display the result. When a command ends in a COLON, the output is suppressed - the computation is carried out but the result is not displayed. This is particularly useful when the output is too large to view conveniently or is only an intermediate result. Unless otherwise asked, please use the semicolon to terminate all commands entered in this tuto = 3:14159265358979323846264338327950n rial. (Note: As a courtesy to those who slip, if 28841971693993751058209749445923n you forget to enter a terminator for any command > Pi=evalf(Pi, 125); 2: NUMBERS, CONSTANTS AND NAMES 5 in this tutorial, one will be appended for you au- One can get examples of how a command is used: tomatically. This *will not* happen outside this > example(expand); tutorial!) Or info about related commands Throughout this tutorial you will see examples of > related(expand); Maple commands printed along the left edge of SEE ALSO: expandoff, expandon, collect, combine, factor, frontend, normal, sort, Expand the worksheet. Often these involve lots of quotes such as `. These normally occur on the left of an = sign and are included in order to give a neater There is also a multi-leveled help topic browser output: by placing quotes around an expression available. This browser allows you to navigate we stop Maple from evaluating it. For example through the dierent Maple help les more in> `sqrt(5)` = sqrt(5); tuitively. To start up the browser, click the left p sqrt (5 ) = 5 button (LB) on the "Help" at the top right of the window and select the "Help Browser" item > `f```(x) = diff(f(x), x); in the menu that will appear. Now click LB on "Mathematics", then "Basic Mathematics", 0f ( x ) = @ f( x ) then "Exponential.." then "Manipulation", then @x "combine". Notice the synopsis given at each stage. Finally click LB on the "Help" button at Any time during this tutorial when you are promptedthe bottom left of the window. for a Maple command (i.e., during the Questions sections or a Quiz) you can ask Maple to display a help le about any particular command - the information will appear in a separate help win- 2 Numbers etc. dow. Make sure to close o these help windows when you are nished with them or you will clut- INTEGERS AND RATIONALS ter up the screen. The following command calls Integers are the most basic exact numbers, while the help screen for the command "expand". rational numbers (fractions) use the division operator to separate numerator and denominator. > ?expand > 3/7; > 2.0/3; As you can see, a help le contains several dier3 ent types of information, such as calling sequence, 7 synopsis, and examples. Use the "scrollbar" on the right of the window to make further infor- > -39/13; ,3 mation visible. Only the left and middle mouse As you can see, rationals are automatically simbuttons have any eect - experiment. plied by Maple. To "kill o" the help window, click the left mouse button on the "File" at its top left hand corner FLOATING-POINT NUMBERS and select the item "Exit" from the menu that Whenever you use a number that contains a decwill appear. imal point, Maple switches from giving exact answers and calculates every quantity in an expresIf all this information is more than you really sion to 10 signicant gures. want, there are also several commands that re- > 2.3; turn only specic parts of a help le. These com2:3 mands include "info", "example", and "related". Following are examples of each for the command > 2/3; "expand". 2 3 > info(expand); FUNCTION: expand - Expand an Expression (Some are more helpful than others) :6666666666 2: NUMBERS, CONSTANTS AND NAMES > 0.143*10^(-44); :1430000000 10,44 6 For example, Pi (pronounced pie): > ```Pi``` = Pi; `Pi ` = which has the decimal value The following examples should illustrate this idea > Pi = evalf(Pi); = 3:141592654 further. Warning: typing the lower case form "pi" is also > 1/3 + 2; printed as the same greek character, but this does 7 not have a predened value: 3 > pi = evalf(pi); > 1/3 + 2.0; = 2:333333333 > 1.0/3 + 2; 2:333333333 Compare > A := Int(exp(-2*x),x=0..1): which evaluates to a symbolic answer > Z 0 1 e( ,2 x ) dx = , 12 e( ,2 ) + 12 B := Int(exp(-2.0*x),x=0..1): for which we get an approximate answer: > > E = evalf(E); > `exp(1)` = exp(1); E = 2:718281828 Note that Maple writes out the value of exp(1) as a lower case e: exp (1 ) = e A = value(A); with > "e" the base of natural logarithms is represented by the upper case "E" B = value(B); Z 1 Maple can work with complex numbers and uses the symbol I to represent the square root of -1: > p I = ,1 It can even work with innity: I = sqrt(`-1`); > ```infinity```= infinity; e( ,2:0 x ) dx = :4323323584 `innity ` = 1 0 The only dierence is that in "B" we replaced the exact constant "2" by the decimal number "2.0". We say that "decimals points are contagious". Be sure to use the proper spelling (including upper and lower letters) when using these constants. QUESTIONS Pi and pi are not the same. Represent the fraction 2345 divided by 34570 in its lowest terms. Names > 2345/34570; A name in Maple, known as an "Identier", is 469 a string of characters starting with a letter (a6914 By adding a decimal point to the value 6/7, get z, A-Z) followed by zero or more letters, digits (0-9), and underscores ( ). Names are casea numerical approximation of that value. sensitive, that is, "MyName" is distinct in Maple > 6/7.0; from "myname". We shall use names in Maple :8571428571 You may get a slightly dierent answer if you either to represent variables (such as x, y, etc) or typed in 6.0/7, since the rounding errors are dif- as "labels" to equations or expressions. ferent. Examples of valid names are: MATHEMATICAL CONSTANTS Some mathematical constants come predened in Maple and may therefore be referred to by their "names" > MyVariable, x2, hello, eqn_1, y[3]; MyV ariable; x2; hello; eqn1; y[3]; Examples of invalid names: 3: MAPLE EXPRESSIONS it contains a \+" it starts with a digit it contains multiple "."s +thequotient 2x ...etc 3 Maple Expressions Maple's arithmetic operators include not only > `+, -, *, 7 3. * and / (equal priority) 4. + and - (equal priority) When there is still ambiguity with operators of equal priority, such as 2/3*4, the expression is evaluated from left to right, so this has the value (2/3)*4, not 2/(3*4). > 2/3*4; 8 3 /`; +; ,; ; = for the four basic arithmetic operators, but also "^" for exponentiation, as in Check the followingresults by hand: In the "equa> `3^2` = 3^2, `x^2` = x^2; tions" shown on the left, expressions in single 3 2 = 9; x 2 = x2 quotes are not evaluated. `4!` = 4!; 4 ! = 24 "abs(..)" for absolute value > `(2+3)*4-5`=(2+3)*4-5; > `x^2/25` = x^2/25; (2 + 3 ) 4 , 5 = 15 Brackets are evaluated rst Use "!" for factorial: > > `abs(-5)` = abs(-5); abs (,5 ) = 5 x 2 =25 = 1 x2 25 The power (^) has priority over division. One is also allowed to group terms together using ROUND BRACKETS (..). Square [..] and curly > `2+3*4-5` = 2+3*4-5; 2 +3 4 ,5 = 9 f...g brackets have particular uses in Maple. Multiplication has higher priority than + or -. The following are some examples of simple Maple > `(2+3)*(4-5)`=(2+3)*(4-5); expressions. (2 + 3 ) (4 , 5 ) = ,5 > a+b+c; a+b+c > 3*x^3-4*x^2+x-7; > x^2/25+y^2/36; 3x ,4x + x,7 3 2 > 2 =3 3 = 2 Left to right evaluation with equal priorities. > 1 x2 + 1 y2 25 36 As you can see, Maple echoes these expressions in a "pretty" form. > Order of Operations. In expressions, the precedence of operators follows the standard found in most other areas of computation. If there are any ambiguities, use parentheses, (), to specify > the order of operations. For example, it is not clear whether 2/3*4 is (2/3)*4 or 2/(3*4) or whether x^2/25 is (x^2)/25 or x^(2/25). Quantities within expressions are evaluated in the following order: 1. Quantities in round brackets () 2. Exponents (powers: ^) `2/3*3`=2/3*3; > `-2^3 + 9`=-2^3 + 9; ,2 3 + 9 = 1 `(2/3^2*5)`=(2/3^2*5); (2 =3 2 5 ) = 10 9 `(2/3^2*5)*(3-4^3)^2`=(2/3^2*5)*(3-4^3)^2; (2 =3 2 5 ) (3 , 4 3 )2 = 37210 9 `3*(3*4-2*5^2-3)`=3*(3*4-2*5^2-3); 3 (3 4 , 2 5 2 , 3 ) = ,123 5: ASSIGNMENTS AND EQUATIONS 8 > ?simplify displays the help information for the command "simplify". Read the information in it (use the 8 "scroll bar" at the right to see all of the text), then kill o the window. It is a good idea to use parentheses whenever Task #2 How would you get examples of how to there is any chance of ambiguity. If a set of use the command "simplify"? parentheses is redundant, Maple will eliminate it automatically. 5 Assignments = & := > `(-2)^3 + 2^(-3)`=(-2)^3 + 2^(-3); (,2 ) + 2 ,3 ) = ,63 3 ( Questions 1. Write the Maple expression that represents the quantity, a plus b, divided by the quantity, a times c. 2. Calculate the value for the binomial formula n!/(n-r)!r! when n=6 and r=2. This section explains the dierence between the assignment operator, := (the colon character followed by the equals sign), and the equation operator, =. It is very important to understand the distinction between the two. Assignments We have previously learned how to create expressions, but these objects are very transitory. Until we actually assign their values to 4 Maple Quiz #1 some holder or variable, they are immediately The followingquiz consists of multiple choice ques- "forgotten" by Maple. For example, if we cretions and others which require you to type in ate an expression and *do not* assign this to a Maple code. The subject matter is drawn from variable name, then each time we wish to use that expression within a Maple command, we have to sections 1-3 of this tutorial. recreate it from scratch. Question #1: Which of the following Maple expressions does NOT give the exact value but eval- If instead, we assign it (with the := operator) uates to a numerical approximation of its ex- to a variable name, then we can easily use it act value? a) Pi; b) 3/4+5/9 c) -2.54*6.78; d) in other calculations or as input to other Maple 7/3*exp(2.4) commands. Question #2: Which of the following IS a valid Maple name? For example, we assign the following expression to the variable "y": b ) %of prot ; a ) Hi there ; > y := (x+1)^4*(x-3); c ) temp variable ; d ) 2late y := ( x + 1 )4 ( x , 3 ) Question #3: Evaluate each of the following as We can now use it as part of another expression decimal numbers (they must be on the same line > z := (y+2*x)/(x-y); 4 separated by commas) 22/7, 333/106, 355/113. z := (xx,+(1x) +( 1x),4 (3x) ,+ 32)x Question #4: Type in a Maple expression to give and the value of "y" has been automatically sub1 2 stituted into the denition of "z". x +x Question #5: At this point both "y" and "z" have been asType in a Maple expression to give p signed values. To remind ourselves of what they x2 , y2 were, we need only type in their names (followed x,y by a semicolon) Question #6: Which is the odd one out: > y; ( x + 1 )4 ( x , 3 ) a) 1=x + 1=y; b)(x + y)=(x y); c) (x + y)=x=y; d)(x + y)=x y? > z; ( x + 1 )4 ( x , 3 ) + 2 x Task #1 The command x , ( x + 1 )4 ( x , 3 ) 5: ASSIGNMENTS AND EQUATIONS > x; > y:='y': 9 ing. One should read this last command as "b becomes equal to a+3" x The last command veries that the "value" of x We made the assignment "b := a+3" - what is is the letter "x"! the eect on b if we give "a" a value? We give "a" the value 2, for example, Bearing in mind that "y" already has a value, > a := 2; if we make a subsequent assignment, then the a := 2 earlier value is lost. For example To check the value of a variable, simply type its > y := sqrt(x-3); name: p > b; y := x , 3 5 so that it has recognised the new value of a, > y; p imilarly x,3 > a := Pi; a := You are not allowed to assign values to certain names because Maple uses these for specic purposes. These include D, E, I, Pi and also the name of any Maple command, such as "di" or "int". If you try to make an illegal assignment a warning will be given: > b; +3 and the value of "b" has changed accordingly. DEASSIGNING VARIABLES In previous sections we have seen how expression can be assigned to variables, such as diff := x - y; Error, (in tut/doflagx) attempting to assign to> b:= c+3; `diff` which is protected b := c + 3 If we later want to use the symbol "b" in its own right rather than have it use the value "c+3", we must rst persuade Maple to forget the assigned value. This we do by giving the variable "b" the value which is the letter 'b': as in Equations The most important thing to realize about equations is that they are not the same as assignments. Equations are simply mathematical expressions that show relationships between certain variables and values; they do not infer any > b := 'b'; b := b explicit values on the variables they contain. For The quotes used here are the "forward quotes" example: which slope upwards from left to right. Now look > b = a + 3; at the value of "b": b =a+3 > > b; b; b So that "b" does not have a value. The equation > b = a + 3; > b - a = 3; > a - b + 3 = 0; b =a+3 could be rewritten in the equivalent forms b,a= 3 a,b+3= 0 But the assignment statement b Earlier in this tutorial we gave both "a" and "y" values so we should also deassign them > y := 'y'; > a := 'a'; y := y a := a It is good practice to deassign variable names as soon as they are no longer required. This frees up the use of that name and can save later confusion. As a variation of a recent example, suppose "a" is given the value 2 and we dene b to have value b := a + 3 cannot be rearranged to give the same mean- > b := a + 3; 5: ASSIGNMENTS AND EQUATIONS "a+3" (rather than doing these steps in the reverse order) > > a := 2; a := 2 10 Equations, once assigned to a name may be manipulated and solved, as in > eqn1 := b = 2*a + 3; > eqn2 := 4*a - 3*b = 2; eqn1 := b = 2 a + 3 b := a + 3; b := 5 so, not unexpectedly, b has value 5. What happens to "b" if we alter the value of "a"? To see the eect, give "a" a dierent value > a := -2; > b; > eqn := y = 2*x +3; a := ,2 Then > eqn2 := 4 a , 3 b = 2 eqn3 := 3*eqn1 + eqn2; eqn3 := 4 a = 6 a + 11 Notice that it does not move terms from the left hand side to the right. We may solve this equation for "a" 5 the value of "b" is unchanged. Why? It is be- > solve(eqn3); ,11 cause "b" was really asigned to "5" since "a" at 2 that time had value "2". The equation contained only one unknown, so > a := 'a': Maple solved for this. It is important to appre> b:='b': ciate that, although we solved this equation for "a", the solution of the equation is not assigned An alternative way of viewing the asignment pro- to "a". cess is to think of variable names as representing > a; specic locations in the computer's memory. If a we use variables "a", "b",...etc, think of these as simply labels on "pigeon-holes" in memory which initially contain the values "a", "b",.. respec- We could have solved the original equations ditively. The assignment rectly by > b := c+3; > solve({eqn1, eqn2}); b := c + 3 then says "take the contents of memory location a = ,211 ; b = ,8 "c" (whatever it contains), add "3" to it and store the result in location labelled "b"." Thus, if "c" The argument to this command is a "set" of had a value prior to the assignment it would af- equations or equation names. In both cases they fect the stored value of "b", otherwise "b" would are contained between curly brackets. have the expression "c+3" as its value. > b:='b': For equations containing more unknowns than equations, we also have to specify which variables EQUATIONS (contd.) With these points in mind, we want to solve for: > eqn1 := b = 2*a + 3*c; we see that an equation, such as eqn1 := b = 2 a + 3 c > y = 2*x + 3; y = 2x+ 3 is not stored anywhere - no assignment has been > eqn2 := 4*a - 3*b = 2; eqn2 := 4 a , 3 b = 2 made - so Maple does not remember the equation (This is not quite true since Maple actually eqn2},{a,c}); remembers the result of many recent commands, > solve({eqn1, 1 1 3 1 but we can recapture only the last 3 unless they c = , 6 b , 3; a = 4 b + 2 were assigned. See the section on " & "" in the handout.) Thus, to remember an equation we so the second argument to the command "solve" have to assign it to a name, as in is a et of unknowns which are to be solved for. eqn := y = 2 x + 3 Finally, in this section, the left and right hand sides of equations may be extracted: > eqn := 2*x + 3*y = 2 + c; 6: Built-in Functions eqn := 2 x + 3 y = 2 + c > lhs(eqn); 2x+ 3y > rhs(eqn); > neweqn:=2*lhs(eqn) + rhs(eqn) = rhs(eqn)^2; > eqn:='eqn'; 2+c and we may dene new equations, like > 11 > log[2](1024); > simplify(log[2](1024)); sin(x), sec(x), sinh(x), sech(x), cos(x), csc(x), cosh(x), csch(x), tan(x) cot(x) tanh(x) coth(x) together with the associated inverse functions neweqn:='neweqn'; arcsin(x) arcsec(x) arcsinh(x) arcsech(x) arctan(y,x) neweqn := neweqn 6 Built-in Functions 10 The trigonometric and hyperbolic functions are neweqn := 4 x + 6 y + 2 + c = ( 2 + c )2 eqn := eqn ln( 1024 ) ln( 2 ) arccos(x) arccsc(x) arccosh(x) arccsch(x) arctan(x) arccot(x) arctanh(x) arccoth(x) Notice that "cosec" is spelt "csc" and the corresponding inverse function is "arccsc". To get a square root - use the function \sqrt" There are two inverse tan functions. The rst is which is the same as "power 1/2" arctan(x) which is the standard function: > sqrt(9); > arctan(-1); 3 , 41 > x^(1/2) = sqrt(x); px = px which gives a result in the range -Pi/2..Pi/2. However, if x = -1 and y = 1 and The function "abs" gives the absolute value: > y:='y': > `abs(-9)` = abs(-9); abs (,9 ) = 9 > theta = arctan(y/x); > sin(2*x)^(1/2); = arctan xy we would want an answer in the second quadrant. To do this, we write "arctan(y, x)": The exponential function is known as "exp(x)": > arctan(1,-1); > exp(-4*x+5); 3 e( ,4 x+5 ) 4 and the natural logarithm (base e) is spelt "ln" (Maple also understands "log" as meaning the > theta:='theta': same thing) > log(Pi); To get powers of trig functions we have to write ln( ) > sin(x)^2; notice the way this has been printed out. sin( x )2 > ln(exp(Pi)); which diers from the way it would be written by hand. Similarly, If you want logs to the base "b" you should use > p sin( 2 x ) log[b](x); ln( x ) ln( b ) For example, for logs base 2: Maple knows the values of trig functions at special angles, such as > sin(pi/2) = sin(Pi/2); 7: Algebraic Manipulation sin 12 = 1 > sin(pi/6) = sin(Pi/6); > cos(pi/6) = cos(Pi/6); > sin 16 = 21 p cos 16 = 12 3 sin(pi/5) = sin(Pi/5); p p sin 15 = 14 2 5 , 5 q 12 What happens if the polynomial does not factorize? > factor(3*x^3-4*x^2+x-7); 3 x3 , 4 x2 + x , 7 We see that it simply returns the polynomial it was given originally. Maple can factorise expressions where the coecients are symbols rather than numbers: > y := a*x^2-a^3*x-x+a^2; > z := factor(y); y := a x2 , a3 x , x + a2 z := ,( a x , 1 ) ( a2 , x ) We have assigned the result of this computation Maple also knows about trig identities but we to the symbol "z" so that we can use it later on. shall deal with these in the next section. > y:='y': Question Factorize the polynomial 10 x3 , 129 x2 + 365 x , 126 7 Algebraic Manipulation The symbol "y" was assigned a value which it retains. To see what this value is, we simply We cover here some simple ways of doing alge- still type braic manipulation using Maple. We shall cover: > y; its name, followed by a semicolon factor factorization of polynomials a x2 , a3 x , x + a2 expand "opposite" of factor Likewise, to see the value of "z" collect collecting terms together > z; simplify apply simplication rules. ,( a x , 1 ) ( a2 , x ) COMMAND: factor Factorization of polynomials The next command assigns a polynomial to COMMAND: expand This is the opposite of facy tor - it expands brackets > y:= 105*x^3-464*x^2+619*x-252; > z; 3 2 y := 105 x , 464 x + 619 x , 252 ,( a x , 1 ) ( a2 , x ) To factorize y, we give the command > factor(y); (3x,7)(7x,9)(5x,4) We could also have been more direct and used > (3x,7)(7x,9)(5x,4) y:= 21*x^4-55*x^3-34*x^2+139*x-63; a x2 , a3 x , x + a2 COMMAND: collect If we now want to collect the terms in "x" together, we use the command "collect" > y; > collect(y,x); > y:='y': y := 21 x , 55 x , 34 x + 139 x , 63 4 > expand(z); factor(105*x^3-464*x^2+619*x-252); Example: > > 3 2 a x2 , a3 x , x + a2 a x2 + ( ,a3 , 1 ) x + a2 ( 3 x , 7 ) ( 7 x , 9 ) ( x2 + x , 1 ) The second argument to this commandtells Maple which does not factorize completely - it has two which variable to use to collect. linear factors and a quadratic factor. factor(y); y := y 7: Algebraic Manipulation 13 The factor command can be used to simplify complicated expressions: > > z := y*(x^2-y^2)/(y^2+x^2)+2*x^2*y/(y^2+x^2) -2*x^2*y*(x^2-y^2)/(y^2+x^2)^2; z := y (yx2 +,xy2 ) + 2 y2x+yx2 , 2 x ( yy2( x+ x,2 )y2 ) 2 2 > factor(z); > simplify(z); 2 2 2 2 Fine, so one would expect > z := sqrt(1 - cos(x)^2); > z = simplify(z, symbolic); > z1 := simplify(z,{cos(x)^2 = 1 - sin(x)^2}); p z := ,cos( x )2 + 1 to behave in the same way: p p ,cos( x )2 + 1 = ,cos( x )2 + 1 , y ( ,x( y+2 y+ x,2 4)2x y ) The root of the problem is that Maple expresses trig functions in terms of "cos" (rather than "sin") We could also use a more general "simplier" whenever possible. To overcome this, called "simplify", as in 4 4 2 2 , y ( ,x( y+2 y+ x,2 4)2x y ) 4 4 2 2 that is, we tell it what trig identity to use but this is still not enough, we need another option to simplify The simplify command has a number of uses, > some of which will be illustrated here by examples. > > p z1 := sin( x )2 z = simplify(z1,radical,symbolic); p ,cos( x )2 + 1 = sin( x ) z := (x^a)*(x^b) + 4^(1/2): p x x + 4 = x( a+b ) + 2 z = simplify(z); a b Trigonometric functions and manipulation Expressions like > z := sin(x+y); z := sin( x + y ) Sometimes, in the course of a computation, on may be expanded obtains an expression containing a term like > z := sqrt(x^2); p z := x2 which one would expect to be automatically simplied to "x". However, Maple is very careful, it presumes that you want the positive square root but it does not know whether x is positive or negative, so the correct answer might be either "+x" or "-x". If simplication to "x" is what one wants, one can tell Maple by adding the option "symbolic" to the simplify command. > z; > z = simplify(z, symbolic); p x2 p2 x =x A similar situation exists with expressions like > z := sqrt(1 - sin(x)^2); p z := 1 , sin( x )2 which you would like to give "cos(x)": the "symbolic" option is again appropriate > z = simplify(z, symbolic); p 1 , sin( x )2 = cos( x ) > z = expand(sin(x+y)); sin( x + y ) = sin( x ) cos( y ) + cos( x ) sin( y ) The opposite command is "combine". Expressions like, > sin(x)*cos(y) + cos(x)*sin(y) + cos(x)*sin(x); > > combine(sin(x)*cos(y)+cos(x)*sin(y)+cos(x)*sin(x), trig); sin( x ) cos( y ) + cos( x ) sin( y ) + cos( x ) sin( x ) may be expressed in multiple angles by sin( x + y ) + 12 sin( 2 x ) Note the second argument which tells it to use "trig" rules. Express > 16*cos(theta)^6-24*cos(theta)^4+6*cos(theta)^2+1; > > combine(16*cos(theta)^6-24*cos(theta)^4 + 6*cos(theta)^2+1,trig); 16 cos( )6 , 24 cos( )4 + 6 cos( )2 + 1 in terms of multiple angles. 1 cos( 6 ) , 3 cos( 2 ) 2 2 Hyperbolic functions are also included under the umbrella of "trig" functions in Maple. Thus, to 8: QUIZ #2 14 express > > 16*cosh(theta)^6 - 24*cosh(theta)^4 + 6*cosh(theta)^2+1; Example (Tutorial 1, Qu. 5) Solve the equation 16 cosh( ) , 24 cosh( ) + 6 cosh( ) + 1 > cosh(2*x) = 11+2*cosh(x); cosh( 2 x ) = 11 + 2 cosh( x ) in terms of multiple angles (we label this expresexpressing your answer in natural logarithms. sion "y" for future use) > y:=combine(16*cosh(theta)^6-24*cosh(theta)^4 We solve the equation and denote the solution by > +6*cosh(theta)^2+1,trig); "S" - recall that solve returns a list of answers. 3 1 y := 2 cosh( 6 ) , 2 cosh( 2 ) > S:=solve(cosh(2*x) = 11+2*cosh(x)); and go back to the original form using expand: S := arccosh( 3 ); arccosh( ,2 ) > expand(y); We may refer to the rst solution as S[1] and the 16 cosh( )6 , 24 cosh( )4 + 6 cosh( )2 + 1 second as S[2]. We now convert the answers to logs (ln) 6 4 2 > convert(S[1],ln), convert(S[2],ln); > z = evalc(z); p p We can convert an EXPRESSION in hyperbolic ln 3 + 2 2 ; ln ,2 , 3 functions to one in terms of exponentials using Notice that the second of these requires the log of "convert(EXPRESSION,exp)": Recall the value a negative number - this requires complex numof y bers. > y; > z := convert(S[2],ln); 1 cosh( 6 ) , 3 cosh( 2 ) p z := ln ,2 , 3 2 2 > y1:=convert(y,exp); 1 1 1 3 3 1 y1 := 4 e( 6 ) + 4 ( 6 ) , 4 e( 2 ) , 4 ( 2 ) e e and simplify it p p z:=simplify(y1); ln ,2 , 3 = ln 2 + 3 + I where "evalc" means "evaluate as a complex number". Recall the value of z These last examples perhaps illustrate how Maple takes the drudgery out of computations but does not do any thinking for you. You have to tell it fairly precisely what it should do. > z := 14 e( 6 ) + 14 e( ,6 ) , 34 e( 2 ) , 43 e( ,2 ) > z; > convert(z,trig); 1 ( 6 ) 1 ( ,6 ) , 3 e( 2 ) , 3 e( ,2 ) 4e + 4e 4 4 We can then convert it back to "trig" form with > 1 cosh( 6 ) , 3 cosh( 2 ) 2 2 y:='y':z:='z':y1:='y1': Example (Tutorial 1, Qu. 4) Show that > cosh(2*x) = (1+tanh(x)^2)/(1-tanh(x)^2); > y:=simplify((1+tanh(x)^2)/(1-tanh(x)^2)); > combine(y,trig); + tanh( x )2 cosh( 2 x ) = 11 , tanh( x )2 We rst simplify the rhs: y := 2 cosh( x )2 , 1 and then use combine: cosh( 2 x ) 8 Maple Quiz #2 The following quiz consists questions drawn from sections 5 - 7 of this tutorial. Question 1. Factorise the polynomial 6 x2 + 18 x , 24 Question 2. Factorise the expression x3 , y3 x4 , y4 Expand the expression ( x2 + x , 1 ) ( x2 + x + 1 ) Express tan(2x) in terms of sin(x) and cos(x). Express sin( x ) cos( y ) in terms of sin(x + y) and sin(x , y) [Hint: com- 9: Dierentiation 15 nds the second derivative of y with respect to x, bine] > 24 x + 12 gives the third. A short cut is to use a $ sign. For example, to nd the 4th derivative, use 9 Dierentiation The command for dierentiation is called "di". > To use it, we have to provide Maple with an expression to dierentiate and tell it which variable to dierentiate with respect to. For example, in > the expression > y:=x^3 + 3*sin(a*x)^2; > diff(y,a); > Diff(y,x); diff(y,x,x,x); diff(y,x$4); y:='y'; 24 y := y y := x3 + 3 sin( a x )2 there are two variables on the right, "x" and "a". Higher partial derivatives The previous discusTo dierentiate with respect to "x": sion was a special case of nding higher partial > diff(y,x); derivatives. With 2 > z := x^2 + 2*y^3 - 6*x*y; 3 x + 6 sin( a x ) cos( a x ) a z := x2 + 2 y3 , 6 x y The second partial derivative with respect to x and y is To dierentiate with respect to "a": > Diff(z,x,y) = diff(z,x,y); @ 2 ( x2 + 2 y3 , 6 x y ) = ,6 6 sin( a x ) cos( a x ) x @y @x So "di(y,x)" means "dy/dx" and "di(y,a)" As expected, reversing the orders of dierentiameans "dy/da". tion gives the same result. > = diff(z,y,x); When the command is spelt with a capital letter Diff(z,y,x) 2 @ as in "Di" - it is recognised as requiring dier( x2 + 2 y3 , 6 x y ) = ,6 @x @y entiation but the operation is not carried out @ ,3 2 @x x + 3 sin( a x ) This is useful in situations such as > Diff(y,x) = diff(y,x); , x3 + 3 sin( a x )2 = 3 x2 + 6 sin( a x ) cos( a x ) a Notice that it prints derivatives as though they were always partial derivatives. @ @x We can give it quite complicated expressions > > > y := (x^2+x-1)*(x^2+x+1); > z:= diff(y,x); > factor(z); y := ( x2 + x , 1 ) ( x2 + x + 1 ) Assign the result to z and nd its factors. z := ( 2 x +1 ) ( x2 + x +1 )+( x2 + x , 1 ) ( 2 x +1 ) 2x(x+ 1)(2x+ 1) > > diff(y,x,x); 4 x2 + 4 x + 2 ( 2 x + 1 )2 cos( y ) Diff(z,x) = diff(z,x); , , 5 sin( x y )3 , 2 e( ,4 x ) cos( y ) = 15 sin( x y )2 cos( x y ) x + 2 e( ,4 x ) sin( y ) z:='z': Find the rst order x-partial derivative of 6 x3 , 2 x2 y + 4 x y , y2 diff(6*x^3-2*x^2*y+4*x*y-y^2,x); That is, 5 sin( x y )3 , 2 e( ,4 x ) cos( y ) = 15 sin( x y )2 cos( x y ) y + 8 e( ,4 x ) cos( y ) Diff(z,y) = diff(z,y); @ @y > Higher derivatives The command z := 5 sin( x y ) , 2 e @ @x > Dierentiate z := 5*sin(x*y)^3 - 2*exp(-4*x)*cos(y); 3 ( ,4 x ) 18 x2 , 4 x y + 4 y 10: INTEGRATION > Diff(Q,x)=diff(6*x^3-2*x^2*y+4*x*y-y^2,x); > d1 + d2; > z:='z': 10 Integration 16 @ 3 2 2 2 @x ( 6 x , 2 x y +4 x y , y ) = 18 x , 4 x y +4 y When integrating an expression we have to Find the rst order y-partial derivative of > diff(exp(x*y)*sin(x^2),y); 1. indicate the variable of integration, x e( x y ) sin( x2 ) 2. specify whether we require denite or inThat is, denite integration. Of course the presence > Diff(Q,y)=diff(exp(x*y)*sin(x^2),y); of limits of integration will distinguish be@ e( x y ) sin( x2 ) = x e( x y ) sin( x2 ) tween these. @y Find the rst order x-partial derivative of > diff(x*y^2*arctan(x*y),x); INDEFINITE INTEGRATION The command name 3 is "int" and it has two arguments; the rst is the y2 arctan( x y ) + 1 +x xy2 y2 expression to be integrated and the second the That is, variable of integration. We shall give a number > Diff(Q,x)=diff(x*y^2*arctan(x*y),x); of examples: @ x y2 arctan( x y ) = y2 arctan( x y )+ x y3 > int(x*sin(x),x); @x 1 + x2 y2 sin( x ) , x cos( x ) or, to get nicer output, > Int(x*sin(x),x)=int(x*sin(x),x); Z If z = arctan(x/y) show that x sin( x ) dx = sin( x ) , x cos( x ) > x*z[x]+y*z[y]=0; x zx + y zy = 0 First assign > z :=< arctan(x/y); You should notice three things: x z := arctan y 1. it does NOT include the arbitrary constant Notice the ":=" of integration, > x*diff(z,x) + y*diff(z,y); 2. it does not reveal the method it used to 0 compute the integral 3. the command "Int" is the so-called inert The last computation was perhaps too "slick" form of the "int" command- it simply prints and so we do it bit by bit: The rst term is out the integral without evaluating it. > d1 := x*diff(z,x); d1 := x 2 > Int(sqrt(x^2-2*x),x) = int(sqrt(x^2-2*x),x); Z y 1 + xy2 p2 x , 2 x dx = and the second term 1 ( 2 x , 2 ) px2 , 2 x, > d2 := y*diff(z,y); x 4 d2 := , 2 p2 , 1 x ln x , 1 + x , 2 x y 1 + y2 2 then add them together 0 See also the Menu Item "Dening Functions" > Int(tanh(x),x) = int(tanh(x),x); Z tanh( x ) dx = ln( cosh( x ) ) > Int(1/sqrt(x^2+x),x) = int(1/sqrt(x^2+x),x); Z p p 21 dx = ln x + 12 + x2 + x x +x 11: QUIZ #3 17 DEFINITE INTEGRATION For denite integration we simply need to include the range of integration. To integrate from x=a to x=b, the range is stipulated by > x = a..b; so we have > x = a::b Z 2 Z xZ x+y,1 0 1 2 y dz dy dx = 32 11 Maple Quiz #3 1. Find the rst x-partial derivative of x2 y , 4 ( x , y )4 2. Find the rst y-partial derivative of x*sin(x): Int(", x=0..Pi)=int(", x=0..Pi); y2 sin( x y2 ) Z 3. Show that x sin( x ) dx = zt = zxx 0 where , 2 , 1=4 xt sqrt(x^2-2*x):Int(",x=2..3) = int(",x=2..3); z := e p Z 3p p p 1 t x2 , 2 xdx = 3 , 2 ln 2 + 3 0 2 4. Evaluate Z 2 x + 1 dx z := Int(tanh(x),x=0..y): x2 , 1 Int(z,x=0..y) = int(z,x=0..y); Z y y 2 5. Evaluate Z 3 2 z := tanh( x ) dx = ln 12 ( e )ey + 1 x + 1 dx 0 2 2 x ,1 z = simplify(convert(value(z),trig)); 6. Evaluate Z Z Z y 1=3 1 tanh( x ) dx = ln( cosh( y ) ) y2 e( x2 ) dx dy int(x*sin(x), x=0..Pi); or, to get nicer output, > > > > > 0 > 1/sqrt(x^2+x):Int(",x=0..1) = int(",x=0..1); Z 1 0 p p 21 dx = ln 23 + 2 + ln( 2 ) x +x 0 3y 12 Plotting with Maple Maple provides a large range of plotting comMULTIPLE INTEGRALS These are computed mands that accommodate most of your scientic by inserting one integral within another: visualization needs. The basic concept to plot> Int( Int(x*sin(y),y=0..x), x=0..Pi) = ting is to provide an expression in one or two > int( int(x*sin(y),y=0..x), x=0..Pi); unknowns, and also provide desired ranges for Z Z x 1 *each* unknown to be evaluated over. Maple 2 x sin( y ) dy dx = 2 + 2 then samples a meaningful set (or grid) of points 0 0 This is the same as the two-step process and displays the results for you. > z := int(x*sin(y),y=0..x); z := ,x cos( x ) + x A separate window is created for each plot, so to perform the inner integration with respect to please make sure that you close these plots win"y", then dows as soon as you are nished viewing them. > int(z, x=0..Pi); This may be done by pointing the mouse into the 1 2 graphics window and typing q. 2+ 2 Two-Dimensional Plots. Expressions in one unBefore going on to the next example we clear the known are plotted using the plot command. There are several types of two-dimensional plots availvalue of "z" able. Here are a few of the more popular ones. > z :='z': > > Int(Int(Int(y,z=2..x+y-1),y=1..x),x=0..2)= int(int(int(y,z=2..x+y-1),y=1..x),x=0..2); You will have to be patient - Maple takes a lit- 12: PLOTTING 18 tle time to build its pictures. The mouse cursor > changes from an arrow to a "watch" symbol while it is "thinking". Refer to the handout (page 6, section 6) on how to include the graphics in your worksheet. plot(x*sin(x)/(1-x), x=0..infinity); Expressions can be plotted: > > 0 0 infinity x with(plots): plot(x^2-3, x=-4..4); 12 It might be preferable in the last example to specify the y-range, this we do by 10 8 6 4 2 -4 0 0 -2 2 x 4 > > plot(x*sin(x)/(1-x), x=0..infinity, y = -2..2); -2 Experiment with the menus available under "Style", "Axes" and "Projection" listed at the top of the graphics window. Recall that this can be done by pointing the mouse into the graphics window and typing a q. We can give a title: > > plot(x*sin(x), x=-10*Pi..20*Pi, title=`y = x*sin(x)`); y 0 0 Parametric expressions can be plotted as well: Suppose that a curve is dened by > y = x*sin(x) 60 {x = sin(t), y = cos(t)}; f x = sin( t ); y = cos( t ) g and t varies from 0 to 2*Pi. 40 > 20 -20 infinity x 0 0 20 40 plot([sin(t),cos(t),t=0..2*Pi]); 60 x -20 -40 1 -60 0.5 -1 We can specify an innite domain > -0.5 00 0.5 1 -0.5 plot(x*sin(x)*exp(-x), x=0..infinity); -1 Lists of x and y values can be joined by lines: > 0 0 infinity x The expressions may have singularities plot([3,3,6,0,3,-3,0,0,3,3], x=-2..10); 12: PLOTTING 19 to see some possibilities. 3 Three-Dimensional Plots Expressions in two unknowns are plotted using the plot3d command. There are several types of three-dimensional plots available. Here are a few of the more popular ones. 2 1 00 -2 2 4 6 8 10 x -1 -2 -3 Expressions can be plotted: > > The values given are in the order: > plot3d((x^2-y^2)/(x^2+y^2), x=-2..2, y=-2..2); [x[1],y[1],x[2],y[2],x[3],y[3]]; and so forth. [x1; y1; x2; y2 ; x3; y3 ] 1 0.5 Multiple plots can be specied for one set of axes: > 0 -0.5 plot({x^2, -x^2, x^2*sin(5*Pi*x)}, x=0..3); -1 -2 -1 y 0 -2 -1 1 1 2 0 x 2 8 6 4 Now point the mouse into the graphics window and hold the left button down and move it around. You will see a cuboid frame move with the mouse. Click the middle button to see the picture again. Maneouvre the surface until you can get a clear view of the behaviour at the origin. Select difoptions from the menus and, after each The set of expressions to be plotted is included ferent choice, Click the middle button in curly brackets f. .. g. 2 0 0 0.5 1 1.5 x 2 2.5 3 -2 -4 -6 -8 expressions can be plotted as well: Besides these standard plots, there are several Parametric > other types of two-dimensional plots available in > plot3d([u*sin(u),u*cos(v),u*sin(v)], u=0..2*Pi, v=0..Pi); the "plots package". This package is loaded by > with(plots): Implicit functions can be plotted in two dimensions: > > implicitplot(x^4+y^8=1, x=-1.5..1.5, y=-1.5..1.5, scaling=CONSTRAINED); 1 y 0.5 -1 -0.5 00 -0.5 0.5 x 1 Questions 1. Plot the function e( ,x2 ) over the range ,5 < x < 5. 2. Plot the function2 ( ,x ) 10 x ) There are several additional options available for over the range e,5 < xsin( < 5. two-dimensional plots. Use the command Include a copy of this picture in your worksheet. ?plot[options] -1 13: SUBSTITUTION Refer to the handout (page 6, section 6). 3. Plot the surface dened by , 2 , 1=4 xt e p t over the rectangle ,5 < x < 5; 0 < t < 1. Include a copy of this picture in your worksheet. Refer to the handout (page 6, section 6). 20 We can begin by trying to factorize it: > factor(p); ( x7 + x6 + 2 x2 + 267 x , 400 ) ( x + 3 )2 from which we see that it has a double real root at x = -3. We can apply the command "solve" to nd the roots: > solve(p, x); RootOf( Z 7 + Z 6 +2 Z 2 +267 Z , 400 ); ,3; ,3 This gives us a list of 3 entries: the repeated 13 Substitution root x=-3 and it also tells us that the remaining roots are a "RootOf" a polynomial of degree 7 We often need to substitute values into an ex- written in terms of the variable " Z" (Maple uses pression. For example, substitute y=2*x-1 into a leading underscore on names it manufactures so as not to conict with any names you might > z := x^2+y^2 -1; want to use.) 2 2 z := x + y , 1 The command is "subs" and has multiple arguments, 1) a list of substitutions we wish to make In order to nd the remaining roots we have to resort to a numerical evaluation. This we can and 2) the expression to substituted into: do with the command "fsolve" - solve to give a > subs(y=2*x-1, z); 2 2 oating point number: x + (2x, 1) , 1 In this way we make the substitution into "z" > fsolve(p, x); 1:411704268; ,3:; ,3: without aecting the value of y outside this exWhich gives us one further root 1.411.... pression - "y" still does not have a value: > y: We can make multiple substitutions: > subs(x=2,y=0,z); 3 We suspect, therefore, that the remaining roots are complex: we suggest this to "fsolve" by adding the argument "complex" > fsolve(p, x, complex); ,2:570881393 , 1:271380957 I; ,2:570881393+ 1:271380957 I; ,:3814383123 , 2:590886218 I; 9 , 25 + ( 2 x , 1 )2 ,:3814383123+ 2:590886218 I; 1:411704268; notice that this does not give the expected (cor1:746467571 , 1:404431855 I; rect) answer - we have to ensure that the "y" 1:746467571+ 1:404431855 I; ,3:; ,3: > subs(x=4/5,y=2*x-1,z); substitution is done rst > subs(y=2*x-1,x=4/5,z); 0 SOLVING EQUATIONS As we have seen in Section 6 Maple is capable of solving systems of equations. It has quite powerful "solve" facilities which will give the exact answers whenever they are possible; in other situations one has to ask for a numerical answer. Find all the roots of the polynomial > > p:=x^9 + 7*x^8 + 15*x^7 + 9*x^6 + 2*x^4 + 279*x^3 + 1220*x^2 + 3*x - 3600; p := x9 + 7 x8 + 15 x7 + 9 x6 + 2 x4 + 279 x3 + 1220 x2 + 3 x , 3600 at we eventually have all the roots. We can also solve systems of nonlinear equations: Solve the equations > x^2+y^2=1, x = y+1; > solve({x^2+y^2=1, x = y+1},{x,y}); x2 + y2 = 1; x = y + 1 Recall that sets of equations have to be placed in curly brackets f: : :g. f x = 1; y = 0 g; f y = ,1; x = 0 g which gives us two points of intersection. Find the stationary points of the surface dened by > z := (x-y)^3+x^2*y^2; z := ( x , y )3 + x2 y2 We rst have to nd the stationary points where 14: DIFFERENTIAL EQUATIONS zx = 0; zy = 0 so we dene the list of equations > eqns := diff(z,x) = 0, diff(z,y) = 0; eqns := 3 ( x , y )2 + 2 x y2 = 0; ,3 ( x , y )2 + 2 x2 y = 0 We solve these and assign the answers to "S" > S := solve({eqns},{x,y}); 21 Example: solve the dierential equation > @ y( x ) = ( x , y( x ) )2 @x We require the general solution. There is only one equation and one unknown: "y(x)": > S[2]; To nd the heights of the surface at these points we substitute the x and y coordinates into z: height1 := subs(S[1],z); > height2 := subs(S[2],z); height1 := 0 height2 := ,432 e C1 + 1 e( ,2 x ) 2 1. You must write "y(x)" for the unknown solution, 2. The arbitrary constant is written as " C1", 3. The solution does NOT assign the solution to the function "y(x)" (the answer was not given in terms of ":="). f x = ,6; y = 6 g > dsolve(diff(y(x),x) = (x-y(x))^2,y(x)); ( ,2 x ) y( x ) = x , 1 + S := f x = 0; y = 0 g; f x = ,6; y = 6 g We can refer to the points as "S[1]" and "S[2]": > Diff(y(x),x) = (x-y(x))^2; Find the solution of > x*Diff(y(x),x) + y(x) = x*(1+y(x)); > de := x*diff(y(x),x) + y(x) = x*(1+y(x)); > ic := y(1)=0; @ x @x y( x ) + y( x ) = x ( 1 + y( x ) ) By evaluating the second derivatives of z at these points we could go on to classify the nature of the that saties initial condition y(1)=0. To stationary points. We leave this as an exercise. be systematic,the we rst make a number of assign> with(plots): ments - the dierential equation (de) > plot3d(z,x=-8..1,y=-1..8); -8 -6 x -4 -2 00 0 2 -100 y 4 6 -200 8 -300 @ de := x @x y( x ) + y( x ) = x ( 1 + y( x ) ) the initial condition (ic) - -400 -500 ic := y( 1 ) = 0 -600 -700 Now solve (the equations making a set): and assign the result to "ans" > 14 Dierential Equations Maple is capable of nding general solutions of a reasonably wide class of dierential equations as well as specic solutions that match given initial conditions. The main command is "dsolve" and its arguments are ans := dsolve({de, ic}, y(x)); ans := y( x ) = ,1 , 1 + 2 e x x xe SECOND ORDER EQUATIONS. The process for nding general solutions is the same as in earlier examples. Find the general solution of > > Diff(y(t),t,t) + 2*Diff(y(t),t) + 5*y(t) = t^2+t; 2 @ @ 1. a set of dierential equations (with starting y( t ) + 2 @t y( t ) + 5 y( t ) = t2 + t 2 @t conditions if these are given) We again split the computation up into smaller 2. a set of function names to solve for. 14: DIFFERENTIAL EQUATIONS 22 bits using an assignment 200 > > de := diff(y(t),t,t) + 2*diff(y(t),t) + 5*y(t) = t^2+t; 150 @ 2 y( t ) +2 @ y( t ) +5 y( t ) = t2 +t de := @t 2 @t > 100 50 dsolve(de,y(t)); 0 0 0.5 1 1.5 x 2 2.5 3 12 + 1 t + 1 t2 + C1 e( ,t ) cos( 2 t ) y( t ) = , 125 25 5 + C2 e( ,t ) sin( 2 t ) Solve the dierential equation The solution has two arbitrary constants " C1" Example: > de:=diff(y(x),x,x) + 16*y(x) =cos(a*x); and " C2". 2 @ de := @x2 y( x ) + 16 y( x ) = cos( a x ) For 2nd order equations with given initial values we proceed as - Find the solution of the initial with y(0) = 1, y'(0) = 0. Investigate the behaviour of the solution for 1) a=3 and 2) a=4. value problem > de:=diff(y(x),x,x) + 4*diff(y(x),x) + 4*y(x) > ic := y(0)=1, D(y)(0)=0; > ic := y( 0 ) = 1; D( y )( 0 ) = 0 = 8*exp(2*x) + exp(-2*x)*sin(x); 2 de := @ 2 y( x ) + 4 @ y( x ) + 4 y( x ) = @x @x We solve the dierential equation and assign the (2x) ( ,2 x ) 8e + e sin( x ) solution to "ans" (this involves using only the with y(0) = 1, y'(0) = 1. right hand side of the answer given by Maple.) > ans := rhs(dsolve({de, ic},y(x))); The new feature involved is how to represent the 1 cos( 4 x ) cos( ( a + 4 ) x ) a initial condition y'(0) = 1. The trick is that ans := 8 a2 , 16 Maple recognises the symbol "D" as represent(a+ 4)x) ing dierentiation. For example, to dierentiate , 12 cos( 4 x )acos( 2 , 16 sin(x), we could write (a, 4)x)a > D(sin)(x); , 81 cos( 4 x ) cos( 2 , 16 a cos( x ) (a, 4)x) , 12 cos( 4 x )acos( 2 , 16 (a,4)x)a We can therefore specify the initial conditions as + 81 sin( 4 x ) sin( 2 a , 16 > ic := y(0)=1, D(y)(0)=1; 1 sin( 4 x ) sin( (a,4)x) ic := y( 0 ) = 1; D( y )( 0 ) = 1 +2 2 , 16 a and then use "dsolve" as usual: (a+4)x)a > dsolve({de, ic},y(x)); + 81 sin( 4 x ) sin( 2 a , 16 y( x ) = 12 e( 2 x ) ,e( ,2 x ) sin( x )+ 12 e( ,2 x ) +2 e( ,2 x ) x 1 sin( 4 x ) sin( ( a + 4 ) x ) ( ,15 + a2 ) cos( 4 x ) ,2 + a2 , 16 a2 , 16 If we want to plot the solution, we assign the solution of the dierential equation to a name, The answer looks very complicated, but if we use "combine" (see section 6) ans, say: > ans := dsolve({de, ic},y(x)); ans := y( x ) = 12 e( 2 x ) , e( ,2 x ) sin( x ) + 12 e( ,2 x ) + 2 e( ,2 x ) x > newans := combine(ans, trig); a x ) ,15 cos( 4 x ) + cos( 4 x ) a newans := , cos( 2 2 2 a , 16 It is much simpler. a , 16 a , 16 to plot the new answer for a = 3: We want to plot the expression on the right hand Now > plot(subs(a=3,newans), x = 0..8*Pi); side of this equation, so > plot(rhs(ans), x = 0..3); 2 14: DIFFERENTIAL EQUATIONS 23 > > 1 0.5 0 0 5 10 15 20 de := diff(u(x),x) = v(x) + sin(x), diff(v(x),x) = -u(x) + cos(x); @ u( x ) = v( x ) + sin( x ); de := @x @ @x v( x ) = ,u( x ) + cos( x ) Notice that we have given two dierential equations separated by a comma. 25 x -0.5 -1 > The result is a "modulated wave" - an oscillatory curve with varying amplitude. S:= dsolve({de},{u(x),v(x)}); S := fv( x ) = cos( x ) x + C1 sin( x ) + C2 cos( x ); u( x ) = cos( x ) + sin( x ) x + C2 sin( x ) + ( , C1 , 1 ) cos( x )g Recall that the new form of the answer is > We assigned the set of solutions to the variable "S", this can be used to extract the solution, in of two ways, rstly, which shows that there is clearly going to be a one > S[1]; problem evaluating this when a = 4. The answer v( x ) = cos( x ) x + C1 sin( x ) + C2 cos( x ) is to take the limit as a -> 4, which can be done by > rhs( S[1] ); > L := limit(newans,a=4); cos( x ) x + C1 sin( x ) + C2 cos( x ) 1 3 but we cannot be sure whether we get "u(x)" or L := x sin( x ) cos( x ) , 2 x sin( x ) cos( x ) "v(x)" this way. A second, better, way is + 8 cos( x )4 , 8 cos( x )2 + 1 > U := subs(S, u(x)); which can be cleaned up by using combine again: U := cos( x )+sin( x ) x+ C2 sin( x )+( , C1 ,1 ) cos( x ) > z:=combine(L,trig); to get the "u" component. 1 > U:='U': z := 8 sin( 4 x ) x + cos( 4 x ) newans; ax) cos( 4 x ) cos( 4 x ) a , cos( a2 , 16 , 15 a2 , 16 + a2 , 16 2 > S:='S': Finally we can plot the solution when a = 4 (the Example: Solve the system of dierential equations solution is assigned to "z" > de1 := diff(u(x),x) = v(x) + sin(x); > plot(z, x=0..8*Pi); @ u( x ) = v( x ) + sin( x ) de1 := @x > 3 2 0 0 5 10 15 x -1 -2 20 25 de2 := diff(v(x),x) = -u(x) + cos(x); @ de2 := @x v( x ) = ,u( x ) + cos( x ) 1 subject to the initial values > -3 ic := u(0) = 1, v(0) = 0; ic := u( 0 ) = 1; v( 0 ) = 0 Notice that we dened the equations separately, this is not signicant, merely an alternative way of specifying them. The solution is obtained in The linear growth of the solution is very evident. much the same way as before > S:= dsolve({de1, de2, ic},{u(x),v(x)}); SOLVING SYSTEMS OF ODEs. S := f v( x ) = cos( x ) x , sin( x ); u( x ) = cos( x ) + sin( x ) x g One may solve systems of dierential equations in Maple in much the same way as single equations. One has to give the "dsolve" command a set of We can plot the two solutions as functions of x equations (including initial conditions if they are by available) and specify a set of unknown functions. > plot(subs(S, {u(x), v(x)}), x=0..10); For example, solve the system of ODEs 15: Quiz #4 24 ,1 + 8 6 4 2 x 0 2 4 6 8 10 0 -2 > e( ,2 t ) C1 + 1 e( ,2 t ) 2 Now deassign y so as not to interfere with subsequent work. -6 -8 (Plot needs a set of expressions to plot). Or > we can plot the points dened parametrically by [u(x), v(x)] using plot( subs(S,[u(x), v(x), x=0..10]) ); 6 4 2 -6 -4 -2 0 2 4 6 8 0 -2 -4 -6 -8 Note the closing square brackets occupies a different position to the earlier curly bracket. Example: Solve the dierential equation > diff(y(x),x) = (x-y(x))^2; @ y( x ) = ( x , y( x ) )2 @x and express the solution as a function y(x); To make the answer into a function requires a number of steps: a) load the student package: > with(student): b) assign the solution of the "dsolve" to a name, Y say > Y :=dsolve(diff(y(x),x) = (x-y(x))^2,y(x)); ( ,2 x ) e C1 + 1 e( ,2 x ) 2 c) Convert the right hand side of this equation into a "procedure" called "y" with argument "x" Y := y( x ) = x , 1 + > y:='y': 15 Quiz 4 1. Use the subs command to substitute y = x+1 into the expression z := x2 , 2 x y + 2 y2 + 3 x = 1 and assign the result to "z1" Solve this to nd the x-coordinates of the points where the curve z is intersected by the line y = x+1. Assign your answer to X How would you get the corresponding y-coordinates? Assign your answer to Y How would you get numerical values for the xcoordinates? 2. Use "solve" to solve the equations x2 , 2 x y + 2 y2 + 3 x = 1; y = x + 1 Assign your answer to "ans" Find all the roots by using "allvalues(ans);" 3. Find the general solution of the dierential equation 2 @ y( x ) + @ y( x ) + y( x ) = sin( x )2 @x2 @x and assign the result to "ans" The answer is very complicated - show that it may be expressed in a simpler form using the command "combine(ans,trig);" 4. Solve theinitial value problem @ 2 y( x ) , @ y( x ) , 2 y( x ) = 5 e( 2 x ) @x2 @x with y(0) = 2, y'(0) = -1. y := makeproc(rhs(Y),x); y := x ! x , 1 + e( ,2 x ) C1 + 21 e( ,2 x ) We can now use "y" as a normal function: > y(t); t,1+ -4 > 1 C1 + 12 y(0); 16 Integration|2 Our earlier treatment of integration dealt only with direct evaluation. In this section we give examples of how one can manipulate integrals and 16: INTEGRATION 2 25 perform operations such as integrating by parts and changing variables. These facilities are provided by the library package "student" and this Evaluate has rst to be read into Maple's memory with: > z := Int(x^2*cos(x),x); Z > with(student): z := x2 cos( x ) dx by integration by parts. We want to dierentiate Integration by parts. This has the form the "x^2" factor, so > Int(u,v) = Zu*v - Int(v,u); Z > z1 := intparts(z, x^2); > z2:=intparts(z1,x); Z u dv = u v , v du z1 := x2 sin( x ) , 2 x sin( x ) dx When we ask Maple to integrate by parts we from which it should be clear we have to inhave to tell it which part of the integrand to dif- tegrate by parts once again, dierentiating, this ferentiate - the "u" bit of the integrand. time, the "x" factor: For the integral > z2 := x2 sin( x ) + 2 x cos( x ) + z := Int(x^k*ln(x),x); Z z := xk ln( x ) dx we want to dierentiate the "ln(x)", so the command is > w := intparts(z, ln(x)); Z ( k +1 ) ( k +1 ) w := ln( xk)+x 1 , xx( k + 1 ) dx This may be simplied with > simplify(w); Z ln( x ) x( k+1 ) , xk dx k+1 and to get its value Z and, nally, >Z , 2 cos( x ) dx z = value(z2); x2 cos( x ) dx = x2 sin( x )+2 x cos( x ),2 sin( x ) Changing variables. Suppose we have the integral > z:=Int(sin(x)/cos(x)^(1/3),x=0..Pi/3); Z 1=3 sin( x ) dx z := cos( x )1=3 0 and we wish to make the change of variable > cos(x)=u^3; cos( x ) = u3 so that u becomes the new independent vari> value(w); able. The command is "changevar" which has 3 ( k +1 ) ( k +1 ) x ln( x ) x , arguments: k+1 ( k + 1 )2 Outwith the tutorial system, you could use value("); 1. the change of variable, since the " means result of preceding computation. 2. the integral to be changed, 3. the new independent variable. > z := Int(x^2*exp(-x),x); Z z := x2 e( ,x ) dx > w1 := intparts(z, x^2); > w2 := intparts(w1, x); w1 := ,x2 e( ,x ) , > > , 2 x e( ,x ) dx Z w2 := ,x e ,x ) , 2 x e( ,x ) + 2 e( ,x ) dx 2 > Z Thus, ( ans := value(w2); 2 ( ,x ) ans := ,x e factor(ans); , 2 x e ,x ) , 2 e( ,x ) ( ,e( ,x ) ( x2 + 2 x + 2 ) z1 := changevar(cos(x)=u^3, z, u); Z u2 du 3 3 1=3 1=2 22=3 ( u ) The result has not been simplied to the extent expected - this is because Maple is unsure of which cube root to take in the denominator, so we use "simplify" with the "symbolic" option: z1 := > 1 z2 := simplify(z1, symbolic); Z 1 u du and the result should now be clear: z2 := 3 > z = value(z2); Z 1=3 0 1=2 22=3 sin( x ) 3 3 1=3 cos( x )1=3 dx = 2 , 4 2 17: FUNCTIONS Use a change of variables to evaluate > z := Int(x^2/sqrt(1-x^2),x); Z 2 z := p x 2 dx 1,x We make the change of variable x = sin(theta): > 26 in which the ranges of integration are inserted. The "y" integral has to be computed rst (since its limits depend on "x"). > z = value(z); Z Z x 0 0 x sin( y ) dy dx = 2 + 12 2 z1 := changevar(x=sin(theta), z, theta); Numerical Values of Integrals sin( )2 cos( ) d p 1 , sin( )2 Integrals such as We have to take care when simplifying this, if > z := Int(exp(sin(x)),x=0..Pi); Z we try z := esin( x ) dx >Zsimplify(z1); 0 , csgn( cos( ) ) cos( )2 + csgn( cos( ) ) d cannot be evaluated analytically. If we try it: z1 := Z > z = value(z); Z Z we get the function "csgn()"|which has the sin( x ) e dx = esin( x ) dx value +1 if > 0 and ,1 if < 0. This indicates 0 0 that Maple does not know whether is positive it simply repeats the question. We can, however, or negative. To get around this we again use the determine its value by "evaluating as a oating "symbolic" option point number" using the command "evalf" > z2:=simplify(z1,symbolic); z2 := Z z3:=combine(z2,trig); z3 := so > Z , 21 cos( 2 ) + 12 d z=value(z3); Z z = evalf(z); Z , cos( )2 + 1 d We now need to express the integrand in terms of double angles > > p x 2 dx = , 41 sin( 2 ) + 12 1,x 2 0 esin( x ) dx = 6:208758036 17 Functions We may dene functions that have a "one-line" denition using the "->" (maps to) notation. An example is > f := x -> x*sin(x); > f(Pi/2); > f(u); f := x ! x sin( x ) which denes "f(x) = x*sin(x)". Thus, we can The "Doubleint" command. This is another way evaluate it at dierent points of setting up double integrals which is a little > f(Pi); easier to use than our previous methods. For 0 example, > z := Doubleint(x*sin(y), y, x); Z Z z := x sin( y ) dy dx gives a double "indenite" integral. To get its value, we give the command: > u sin( u ) z = value(z); Z Z x sin( y ) dy dx = , 12 cos( y ) x2 For denite integration: > 1 2 z := Doubleint(x*sin(y), y=0..x, x=0..Pi); Z Z x z := x sin( y ) dy dx 0 0 You should pay particular attention to the order The function may be dierentiated: > diff(f(x),x); or > sin( x ) + x cos( x ) diff(f(u),u); sin( u ) + u cos( u ) 18: Linear Algebra 27 left expressions, > g := x -> cos(x+a); > > > > f(g(v)); > > g(f(v)); > f:='f':g:='g': If we dene a second function g := x ! cos( x + a ) Then we can form the composition cos( v + a ) sin( cos( v + a ) ) cos( v sin( v ) + a ) Now "undene" f and g: Functions of two variables. These are dened in a similar way, for example r := x^2*diff(f(x,y),x$2) + 2*x*y*diff(f(x,y),x,y) + y^2*diff(f(x,y),y$2) - 6*f(x,y); factor(r); r := ,4 x2 y + 2 x y ( 2 x + 6 y ) , 12 x y2 0 18 Linear Algebra We introduce matrices, vectors and various operations that may be carried out, such computing determinants, solving linear equations and computing eigenvalues and eigenvectors. > f := (x,y) -> g(x-y); > > Diff(`f(x,y)`,x) + Diff(`f(x,y)`,y) = diff(f(x,y),x) + diff(f(x,y),y); > with(linalg); > f:='f': > > A := matrix(3,3, [1,a,-a^2,1,b,b^2,1,c,c^2]); f := ( x; y ) ! g( x , y ) where g is an arbitrary function, we can compute Many operations involving matrices require the "linalg" package, which is loaded by the comfx + fy mand with(linalg); The list printed out gives the names of all the new commands that have been > diff(f(x,y), x) + diff(f(x,y),y); dened. Use the "?" help feature to discover 0 more about these commands: e.g. ?linsolve that is Warning: new definition for norm @ f (x ; y ) + @ f (x ; y ) = 0 Warning: new definition for trace @x @y where we have put backward quotes around f(x,y) on the lhs to stop it being evaluated as g(x-y). MATRICES We can construct matrices of a specied size by the command: Questions 1. Dene a function f(x,y) so that f (x ; y ) = x2 y + 3 x y2 > f:=(x,y)->x^2*y+3*x*y^2; f := ( x; y ) ! x2 y + 3 x y2 Hence prove that x fx + y fy = 3 f > > r := x*diff(f(x,y), x) + y*diff(f(x,y),y) - 3*f(x,y); r := x ( 2 x y + 3 y2 ) + y ( x2 + 6 x y ) , 3 x2 y , 9 x y2 > factor(r); 2 3 1 a ,a2 7 6 A := 664 1 b b2 775 1 c c2 which denes a 3 by 3 matrix. Note that the order in which the elements are listed is "rowwise". To recall the value of a matrix, we cannot simply type its name, as for other variables A; we have to use either > print(A); 2 6 6 6 4 0 or, more briey, Show also2 that 2 > op(A); x fxx + 2 x y fxy + y fyy = 6 f Let r denote the dierence between the right and 1 a ,a2 1 b b2 1 c c2 3 7 7 7 5 18: Linear Algebra 2 6 6 6 4 28 1 a ,a 1 b b2 1 c c2 2 have been dened earlier 3 > 7 7 7 5 print(A); 2 6 6 6 4 1 a a2 1 b b2 1 c c2 3 7 7 7 5 ELEMENTS of MATRICES To extract the ele- > print(v); ment in the ith row and jth column of a matrix [ a3 b3 c3 ] A, we use A[i,j] - with square brackets. The command we need is "linsolve" > A = op(A); 2 A= 6 6 6 4 > A[1,2], A[3,3]; > A[1,3] := a^2; > A = op(A); 1 a ,a2 1 b b2 1 c c2 3 7 7 7 5 a; c2 We can then change individual elements: A1;3 := a2 2 6 A = 664 1 a a2 1 b b2 1 c c2 3 7 7 7 5 > x := [ c b a , b a , b c , c a b + a + c ] where we have assigned the result - a COLUMN vector - to "x". MATRIX PRODUCTS With A dened as before and B dened by > d := det(A); > factor(d); B:=matrix(3,2,[0, b, -1,-a, 1,0]); 2 C := evalm( A &* B); 2 ,a + a2 b , a2 6 C := 664 ,b + b2 b , b a ,c + c2 b , c a d := b c2 , b2 c , a c2 + a2 c + a b2 , a2 b which we may factorize: ( ,c + a ) ( ,c + b ) ( b , a ) 3 0 b 7 6 6 B := 64 ,1 ,a 775 1 0 To compute the product A.B we have to use "&*" instead of the usual "*" for multiplication (since multiplication for matrices is not commutative, that is AB is NOT equal to BA). To evaluate the result, use "evalm" - evaluate as a matrix (NOTE: A*B will not work); DETERMINANTS To compute the determinant > of A: > x := linsolve(A,v); 3 7 7 7 5 and the result, C, is a 3 by 2 matrix. MATRIX TRANSPOSE To transpose a matrix rows with the corresponding columns) VECTORS Constructing vectors is similar to ma- (interchange > op(B); trices 2 3 > v := vector(3,[a^3, b^3, c^3]); 0 b 6 7 6 7 v := [ a3 b3 c3 ] 6 ,1 ,a 7 4 5 It is important to appreciate that, contrary to 1 0 appearances, this is a COLUMN vector. In this example the rst argument "3" to vector, which > species its dimension, could be omitted since we transpose(B);2 3 have given a list of precisely 3 entries. The "i"th 0 , 1 1 4 5 entry of v is v[i] b , a 0 > v[3]; Then we may compute c3 > SOLVING LINEAR EQUATIONS Suppose we wish to solve the system Ax=v, where A and v evalm(transpose(B) &* A); 2 4 ,b + c ,b2 + c2 b , a 0 a2 b , a b2 0 3 5 18: Linear Algebra 29 terms. The rst term > V[1]; > lambda[2] = V[2][1], multiplicity[2] = V[2][2]; > Y[2] := V[2][3]; > Z:=transpose (matrix([op(Y[1]),op(Y[2])]) ); EIGENVALUES We can construct the charac[ 3; 1; f [ 11 0 ] g ] teristic polyomial of a matrix dened by det(A is a list made up of 3 items, the eigenvalue, its - lambda*I), where I is the identity matrix. Be- multiplicity and a corresponding set of eigenvalfore giving illustrations, we dene a more suitable ues. matrix A > A:=matrix(3,3,[1,-1,0,-1,2,-1,0,-1,1]); 2 3 We may extract the information by 1 , 1 0 > lambda[1] = V[1][1], multiplicity[1] = V[1][2]; 6 7 6 7 1 = 3; multiplicity1 = 1 A := 64 ,1 2 ,1 75 0 ,1 1 > Y[1] := V[1][3]; Then Y1 := f [ 1 1 0 ] g > p:=charpoly(A,lambda); p := 3 , 4 2 + 3 constructs the characteristic polyomial with independent variable "lambda". 2 = 9; multiplicity2 = 2 Y2 := f [ ,2 1 0 ]; [ 0 01 ] g Factorizing the characteristic polyomial "p" we There is a simple eigenvalue at 3 with eigenvector nd > [1,1,0]; > factor(p); [ 1; 1; 0 ] (, 1)(, 3) and a double eigenvalue at 9 with eigenvectors from which the eigenvalues are evident. > [-2,1,0], [0,0,1]; [ ,2; 1; 0 ]; [0; 0; 1] It is possible to determine the eigenvalues directly using the command "eigenvals". > eigenvals(A); The 3 eigenvectors are contained in Y[1] and the 0; 3; 1 set Y[2]. Then 2 3 1 ,2 0 7 The command "eigenvects" computes the eigen6 6 vectors but the output needs some care in decodZ := 64 1 1 0 775 ing: 0 0 1 > eigenvects(A); the matrix, each of whose columns is [ 1; 1; f [ ,1 0 1] g ]; [ 0; 1; f [1 1 1] g ]; [ 3; 1; f [1 ,2 1 ] gconstructs ] It is split into three lists (corresponding to the an eigenvector of C. Hence, Z diagonalises C, as number of distinct eigenvalues of A). For exam- in Z); ple, the last item is the list [3, 1, [1,-2,1]] in which > evalm(inverse(Z) 2 &* C &* 3 the rst number (3) is the eigenvalue the second 3 0 07 6 (1) its multiplicity The third item is the set of 6 7 6 0 9 0 7 associated eigenvectors, in this case there is just 4 5 the single eigenvector [1,-2,1] 0 0 9 Determine the eigenvalues and eigenvectors of the SUBSTITUTION INTO MATRICES Suppose we matrix wish to make the substitutions > C:=matrix(3,3,[7,-4,0,-2,5,0,0,0,9]); 2 3 > a = 1, c = b^2; 7 ,4 0 7 a = 1; c = b2 6 6 7 C := 64 ,2 5 0 75 into > A := matrix(3,3,[1,a,-a^2,1,b,b^2,1,c,c^2]); 2 3 0 0 9 2 1 a , a 6 7 > V := eigenvects(C); 6 7 2 A := 6 1 b 7 b V := [ 3; 1; f [ 1 10 ] g ]; [ 9; 2; f [ ,2 1 0]; [ 0 01 ] g ] 4 5 1 c c2 The result, labelled V, is a sequence with two 18: Linear Algebra 30 We have to substitute into the contents of the Gauss Jordan algorithm matrix labelled "A", i.e. into "op(A)" > gaussjord(TI,'R'); 2 > subs(a = 1, c = b^2, op(A)); 4 3 2 1 3 2 3 1 0 0 0 6 5 5 5 5 77 6 1 1 ,1 7 6 6 3 6 4 2 77 6 6 2 7 6 0 1 0 0 6 1 b 7 b 5 5 5 5 777 6 4 5 6 6 1 b2 b4 2 4 6 3 77 6 0 0 1 0 6 5 5 5 5 77 6 4 5 0 0 0 1 15 25 35 54 CONSTRUCTION OF SPECIAL MATRICES Suppose we wish to construct the 3 by 3 matrix hav- The second argument, 'R', enclosed in forward ing (i,j) entry dened by 1/(i+j-1). The deni- quotes, returns the rank of the augmented matrix tion of the entries is given as a function so we > R; may use 4 > H := matrix(3,3,(i,j) -> 1/(i+j-1)); 2 6 6 6 := 66 6 4 1 1 2 1 3 1 2 1 3 1 4 1 3 1 4 1 5 3 7 7 7 7 7 7 5 Question #1: Construct the following matrix and label it Q1 2 H 3 1 , 2 , 1 6 7 6 7 6 ,1 7 1 1 4 5 1 0 ,1 Two more complicated examples which makes Question #2: The matrix Q1 was dened in the use of conditional statements previous question (and still retains its value), use > Id := matrix(4,4,(i,j)-> if i=j then 1 else 0the fi); Help system to nd out about the command 2 3 "rank" and hence compute the rank of Q1. 1 0 0 07 6 6 7 Question #3: Reduce the matrix Q1 to row ech6 0 1 0 0 7 6 7 Id := 6 elon form and conrm the value obtained by the 7 6 0 0 1 0 7 "rank" command. 4 5 0 0 0 1 Question #4: The matrix Q1 has3 the value 2 gives the 4 by 4 identity matrix 1 ,2 ,1 7 6 > T := matrix(4,4, 6 > (i,j) -> if i=j then 2 6 ,1 1 1 775 4 > elif abs(i-j)=1 then -1 > else 0 fi); 1 0 ,1 2 3 2 ,1 0 0 7 Change its (1,3) entry to have the value a. 6 6 7 6 ,1 2 ,1 0 77 Question #5: What is the determinant of Q1? T := 66 7 6 0 ,1 2 ,1 75 Question #6: Construct the following matrix and 4 label it A 2 3 0 0 ,1 2 2 1 3 , 1 6 7 6 7 6 ,4 ,3 ,4 7 5 6 7 The command "augment(T, Id)" constructs the 6 7 6 6 7 4 4 , 5 matrix [T, Id] 4 5 > TI := augment(T, Id); , 4 , 3 2 4 2 3 2 , 1 0 0 1 0 0 0 Construct the following column vector and label 6 7 6 7 it b h i 6 ,1 2 ,1 0 0 1 0 0 77 TI := 66 3 2 , 1 7 7 6 0 ,1 2 ,1 0 0 1 0 75 4 Hence solve the linear system Ax = b. 0 0 ,1 2 0 0 0 1 Question #7: Determine the eigenvalues and eigenvectors of the matrix labelled P We may reduce this to row echelon form by the 19: CALCULUS OF SEVERAL VARIABLES 2 6 6 6 6 6 6 4 7 1 1 ,1 1 7 ,1 1 1 ,1 7 1 ,1 1 1 7 3 7 7 7 7 7 7 5 31 Maple also has an alternative notation using the "D"- operator. For a function f(x) of one variable, D operates on the name "f", so is written > q := D(f)(x); q := D( f )( x ) We can convert it to a familiar form: Question #7a: How many distinct eigenvalues > q = convert(q, diff); @ f( x ) does P have? D( f )( x ) = @x Question #7b: What are their values? (type smallest rst, separated by commas) For the 4th derivative we would write 19 Calculus of Several Variables Dierentiation > q := (D[1,1,1,1])(f)(x); q := D1;1;1;1( f )( x ) or, equivalently, > > q := (D[1$4])(f)(x): q = convert(q, diff); @ 4 f( x ) D1;1;1;1( f )( x ) = @x To begin, let us suppose that we have an expres- the "1" signies dierentiation4 with respect to sion involving just two variables, x and y, such the rst argument of f - i.e. x which is repeated as 4 times. > f := x^4*y^3; f := x4 y3 notation extends to functions of more than which we have labelled f. We may dierentiate This one variable, as in it using "di": > Diff(f,x) = diff(f,x); > Diff(f,y) = diff(f,y); @ x4 y3 = 4 x3 y3 @x for the rst x-partial derivative, and @ x4 y 3 = 3 x4 y 2 @y for the rst y-partial derivative. Higher derivatives are obtained similarly: > Diff(f,x,x,x,y,y) = diff(f,x,x,x,y,y); @ 5 x4 y3 = 144 x y @y2 @x3 and this may be abbreviated to > Diff(f,x$3,y$2) = diff(f,x$3,y$2); > q := (D[1,1,1,2,2])(f)(x,y): where "1" signies dierentiation with respect to the rst argument of f (i.e. x) and "2" signies y-derivative. > q = convert(q, diff); D1;1;1;2;2( f )( x; y ) = @y2@ @x3 f( x; y ) 5 > > q := (D[1$3,2$2,3$4])(f)(x,y,z): q = convert(q, diff); @9 D1;1;1;2;2;3;3;3;3( f )( x; y; z ) = @y2 @z f( x; y; z ) 4 @x3 > q:='q': Question 1. What is2 the third derivative of @ 5 x4 y3 = 144 x y e( ,3 x y ) sin( x ) @y2 @x3 The "x$3" produces "x,x,x" - i.e. 3 repetitions with respect to x? > diff(Q,x$3); of "x". Now clear the denition of f: > f:='f': 108 y2 x e( ,3 x2 y ) sin( x ) , 18 y e( ,3 x2 y ) cos( x ) , 216 x3 y3 e( ,3 x2 y ) sin( x ) We often want to work with arbitrary functions, such as f(x,y), which do not have an explicit def+ 108 x2 y2 e( ,3 x2 y ) cos( x ) inition: + 18 x y e( ,3 x2 y ) sin( x ) , e( ,3 x2 y ) cos( x ) > diff(f(x,y), x$3, y$2); @ 5 f( x; y ) 2 @y @x3 19: CALCULUS OF SEVERAL VARIABLES > Question 2. What command gives: @ 3 g( u; v ) @v @u2 > > @ 3 g( u; v ) @v @u2 diff(g(u,v),u$2,v), convert((D[1,1,2])(g)(u,v),diff); @ 3 g( u; v ); @ 3 g( u; v ) @v @u2 @v @u2 The Jacobian Matrix: In order to use Maple to dierentiate both scalar and vector functions of one or more variables we have the command jacobian, which has the general form > `f```(x) = jacobian([x^2*sin(a*x)], [x]); h f`( x ) = 2 x sin( a x ) + x2 cos( a x ) a i b) Scalar function of 2 variables: Diff(g(u,v),u$2,v); alternatives are > > 32 'jacobian([list1],[list2])'; jacobian( [ list1 ]; [ list2 ] ) where "[list1]" is a list of expressions to be dierentiated, you should think of them as the entries of a COLUMN vector. "[list2]" is a list of the variables to dierentiate with respect to ([x,y] for instance). jacobian([f(x,y)], [x,y]); h i f( x; y ) @y@ f( x; y ) which is a ROW vector ( a matrix with one 1 row and 2 columns). @ @x Example: nd the rst derivative of q( x; y ) = [ x y3 ; x2 y ]T The answer is > `q```(x,y) = jacobian([x*y^3, x^2*y], [x,y]); 2 y3 3 x y2 q`( x; y ) = 4 2 x y x2 3 5 c) Vector function of 1 variable. Suppose that the vector has entries a(x) and b(x): q( x ) = [ a( x ); b( x ) ]T then > `q```(x) = jacobian([a(x), b(x)], [x]); 2 3 a( x ) 5 q`( x ) = b( x ) The "jacobian" command needs the linear algewhich has 2 rows and 1 column. bra library, which is loaded by:: > with(linalg): Warning: new definition for Warning: new definition for norm trace So we can get: > jacobian([f(x,y), g(x,y)], [x,y]); 2 x; y ) @ @x g( x; y ) f( 4 @x @ @ @y @ @y f( x; y ) g( x; y ) 3 5 We can use the jacobian command to dierentiate a variety of scalar/vector functions. a) Scalar function of 1 variable: Note the square brackets around entries, these are essential. > jacobian([f(x)], [x]); h i f( x ) The result also has square brackets around it -think of it as a matrix, in this case, one by one. @ @x Example: Find the derivative of f( x ) = x2 sin( a x ) with respect to x. The answer is: @ 4 @x @ @x d) Vector function of 2 variables: Suppose that the vector has entries a(x,y) and b(x,y), then q( x; y ) = [ a( x; y ); b( x; y ) ]T then > `q```(x,y) = jacobian([a(x,y), b(x,y)], [x,y]); 2 a( x; y ) @y@ a( x; y ) q`( x; y ) = b( x; y ) @y@ b( x; y ) which has 2 rows and 2 columns. @ 4 @x @ @x 3 5 In general, the result of using the command "jacobian" will be an m by n matrix where m, the number of rows, is equal to the dimension of the function being dierentiated and n, the number of columns, is equal to the number of variables. > jacobian([a(x,y,z), b(x,y),c(x)], [x,y,z]); @ a( x; y; z ) ; @ a( x; y; z ) ; @ a( x; y; z ) @x @y @z @ b( x; y ) ; @ b( x; y ) ; 0 @x @y @ c( x ) ; 0 ; 0 @x 20: MAPPINGS 33 For example, for the transformation to polar coordinates, let U = [r, theta] then we can dene the transformation function g by Example: Find the derivative f'(t) of f( t ) = [ t2; e( 3 t ) ]T Answer: > `f```(t) = jacobian([t^2,exp(3*t)], [t]); 2 3 2t f`( t ) = 4 ( 3 t ) 5 3e Note: a) the arguments to jacobian are LISTS and b) the use of "exp" for the exponential function. Example: Find the derivative f' of f( x; y ) = [ e( ,x ) sin( y ); e( ,y ) cos( x ) ]T Answer: > > > g:= U -> [U[1]*cos(U[2]),U[1]*sin(U[2])]; > g( [r, theta]); > g([1,Pi]); g := U ! [U1 cos (U2 ) ; U1 sin (U2 )] where U[1] represents the rst component of U, and U[2] the second component. Remember that the argument to g is a vector, so must be enclosed in square brackets:: Contrast with 2 3 5 20 Mappings in 2 Variables [U1 cos (U2 ) ; U1 sin (U2 )] which assumes that U is a vector. It is sometimes convenient to dene a vector, such as, > x = r*cos(theta), y = r*sin(theta); x = r cos( ); y = r sin( ) We shall give an illustration of this mapping along with others before considering the eect of such changes of coordinates on functions of several variables. We shall then turn to discuss how derivatives of functions are changed under transformations. with(linalg): Warning: new definition for Warning: new definition for norm trace R:=vector([r,theta]); then we can use It is quite common to have to change coordi- > nates in the course of a mathematical computation. For example, we may wish to change from Cartesian coordinates (x,y) to polar coordinates > (r,theta), dened by > [ ,1; 0 ] `f```(x,y) = jacobian( > [exp(-x)*sin(y), exp(-y)*cos(x)], [x,y]); g(U); ,e( ,x ) sin( y ) e( ,x ) cos( y ) f`( x; y ) = 4 ( ,y ) ,e sin( x ) ,e( ,y ) cos( x ) > [ r cos( ); r sin( ) ] > > g(R); R := [ r ] [ r cos( ); r sin( ) ] with(plots): setoptions(color=black,scaling=constrained, symbol=circle): In order to visualise the transformation we may take a set of points in the (r,theta) plane and work out where they are mapped to by the function g. For example, take 4 points with the (r,theta) coordinates > points:=[[0.1,1], [0.2,1],[0.2,1.3],[0.1,1.3]]; points := [ [ :1; 1 ]; [ :2; 1 ]; [ :2; 1:3]; [ :1; 1:3] ] which are the vertices of a rectangle. We plot these with > > > plot(points,r=0..0.25,theta=0..1.4, scaling=unconstrained, Perhaps the rst issue to be addressed is how we title=`Points in (r,theta) plane`); can represent transformations in Maple. Let us dene X to be the vector with two components (We have joined the points up to make them easx,y and similarly, U the vector with components ier to see.) u, v. If we change from (x,y) to (u,v), then we require a denition of a mapping between the vectors X and U, we shall suppose that X is dened in terms of U: X = g( U ) say. 20: MAPPINGS 34 Points in (r,theta) plane Grid in (u,v) plane 1.4 2 1.2 1.5 1 0.8 v 1 theta 0.6 0.4 0.5 0.2 0 00 0.05 0.1 0.15 0.2 0.25 0 1 0.5 The mapped coordinates may be computed individually by 1.5 2 u r for a 10 by 10 grid on the square 0<u<2, 0<v<2. > newpoint1:=g([0.1,1]); Our rst example looks at the eect of the linear transformation > newpoints := map( g, points); > L([u,v]); > > > > > > plot3d([L([u,v])[1],L([u,v])[2],0], u=0..2,v=0..2,axes=normal, grid=[10,10],orientation=[-90,0], shading=none,labels=[x,y,z],thickness=2, labelfont=[TIMES,BOLD,14], title=`Grid in transformed coordinates`); newpoint1 := [ :1 cos( 1 ); :1 sin( 1 ) ] and so on, but we can apply g to each pair of > L:=U->[U[1]-U[2], U[1]+U[2]]: coordinates in the list using That is newpoints := [[ :1 cos( 1 ); :1 sin( 1 ) ]; [ :2 cos( 1 ); :2 sin( 1 ) ]; [ :05349976572; :1927116371 ]; [ :02674988286; :09635581854]] and plot them with > > plot(newpoints,x = 0..0.2,y =0..0.2, title=`Mapped points in (x,y) plane`); [ u , v; u + v ] We take a grid of 10 by 10 points in the square 0 < u,v < 2 and to plot the mapped grid we use Grid in transformed coordinates Mapped points in (x,y) plane 4 0.2 3 0.15 y 2 y 0.1 1 0.05 -2 -1 0 0 1 2 x 00 0.05 0.1 x 0.15 0.2 The eect is to rotate the original grid through It is often instructive to see how the mapping 45 degrees counterclockwise and to expand the transforms a larger grid of points which are equally area of each grid cells by a factor: spaced in the original space. We can do this with > det(jacobian(L([u,v]),[u,v])); 2 Maple's "plot3d" command. In the (u,v) plane, the grid looks like > > > > > > plot3d([u,v,0],u=0..2,v=0..2, axes=normal,grid=[10,10], orientation=[-90,0],shading=none, labels=[u,v,z],thickness=2, labelfont=[TIMES,BOLD,14], title=`Grid in (u,v) plane`); Using the transformation g dened earlier which transforms to polar coordinates, > g([r,theta]); > > > > > > plot3d([g([u,v])[1],g([u,v])[2],0], u=0..2,v=0..3*Pi/2,axes=normal,grid=[10,10], orientation=[-90,0],shading=none, labels=[x,y,z],thickness=2, labelfont=[TIMES,BOLD,14], title=`Grid in polar coordinates`); [ r cos( ); r sin( ) ] we take a 10 by 10 grid 0<r<2, 0 < theta < 3*Pi/2 21: TRANSFORMING DERIVATIVES 35 A nal example Grid in polar coordinates 2 > H:=U->[U[1]^2-U[2]^2,2*U[1]*U[2]]; > > > > > plot3d([H([u,v])[1],H([u,v])[2],0],u=0..2,v=0..2, axes=normal,grid=[10,10],orientation=[-90,0], shading=none,labels=[x,y,z],thickness=2, labelfont=[TIMES,BOLD,14], title=`Grid in transformed coordinates`); 1 -2 -1 y 0 0 1 2 x -1 -2 H := U ! U1 2 , U2 2 ; 2 U1 U2 Grid in transformed coordinates 8 Now dene another mapping by > 6 G:=U->[(U[1]+U[2])/2,(U[1]-1)^2*U[2]/4]; G := U ! 12 U1 + 12 U2; 14 (U1 , 1)2 U2 so that > y 4 2 -4 G([u,v]); -2 0 0 2 4 x 1 u + 1 v; 1 ( u , 1 )2 v 2 2 4 These transform the grid of 10 by 10 points in the jacobian of the transformation is > j := jacobian(H([u,v]), [u,v]); the square 0 < u,v < 2 and to 2 3 > plot3d([G([u,v])[1],G([u,v])[2],0],u=0..2,v=0..2, 2 u , 2 v > axes=normal,grid=[10,10],orientation=[-90,0], 5 j := 4 > shading=none,labels=[x,y,z],thickness=2, 2 v 2 u > labelfont=[TIMES,BOLD,14], > title=`Grid in transformed coordinates`); and its determinant > 0.5 0.4 0.3 Clear function denitions: y 0.2 > 0.1 0 det(j); 4 u2 + 4 v2 is clearly non-zero at all points except the origin. Grid in transformed coordinates 0 0.5 1 1.5 g:='g':f:='f':H:='H':G:='G': 2 x 21 Transforming Derivatives We see in this case that the lines have become with(linalg): tangled - this is evidence that the mapping is >Warning: definition for norm singular - there are points where the determinant Warning: new new definition for trace of its jacobian matrix is zero. Point the mouse into the graph just produced, hold the left button down, move the mouse, then click on the middle Another important feature of mappings from (x,y) coordinates to (u,v) coordinates is the ability to button. relate derivatives in one coordinate system to derivatives in the other. We now compute the jacobian determinant: > dG := det(jacobian(G([u,v]), [u,v])); dG := 18 u2 , 14 u + 18 , 14 v u + 41 v and factorize the result: Let the transformation X=(x,y) -> U=(u,v) be dened by X = T(U) where > T:=U->[x(U[1],U[2]),y(U[1],U[2])]; T := U ! [x (U1 ; U2) ; y (U1 ; U2 )] 1 so that , 8 ( u , 1 ) ( ,u + 1 + 2 v ) = T([u,v]); so that it is seen to be zero along the lines u=1, > 'T([u,v])' T( [ u; v ] ) = [ x( u; v ); y( u; v ) ] u = 1+2v and this is the reason for the tangling and x(u,v), y(u,v) are given functions. We have of the grid. > factor(dG); 21: TRANSFORMING DERIVATIVES 36 dened T in such a way that its argument is a > g(u,v) = (f@T)([u,v]); list U = [ U[1], U[2] ]. The mapping from with g( u; v ) = f( [ x( u; v ); y( u; v ) ] ) U=[u,v], is obtained with (square brackets on the rhs) where @ denotes > T([u,v]); composition of functions. How are the (x,y) deriva[ x( u; v ); y( u; v ) ] tive of f(x,y) related to the (u,v) derivatives of g(u,v)? or, for U=[ a, b], > T([a,b]); [ x( a; b ); y( a; b ) ] We rst remind ourselves of the derivatives of g, f and T: The square brackets are essential, compare the previous result with > > T(a,b); > [x (a1; a2 ) ; y(a1; a2)] The Jacobian matrix of the transformation T is > jacobian(T([u,v]),[u,v]); 2 x( u; v ) @v@ x( u; v ) y( u; v ) @v@ y( u; v ) which is a function of (u,v). @ 4 @u @ @u 3 5 > `g``` = jacobian([g(u,v)],[u,v]); g` = h @ @u g( u; v ) g( u; v ) @ @v `f``` = jacobian([f(x,y)],[x,y]); h f`= @ @x f( x; y ) f( x; y ) @ @y `T``` = jacobian(T([u,v]),[u,v]); 2 @ 4 @u @ @u T` = x( u; v ) y( u; v ) @ @v @ @v x( u; v ) y( u; v ) i i 3 5 Example: polar coordinates We want x 7! r cos(),yWe 7! rst dierentiate both sides of the equation r sin(), so, with U[1] = r, U[2] = theta, dene > g(u,v) = '(f@T)'([u,v]); > T := U-> [U[1]*cos(U[2]),U[1]*sin(U[2])]; g( u; v ) = ( f @T )( [ u; v ] ) T := U ! [U1 cos (U2 ) ; U1 sin (U2 )] with respect to the components of [u, v] using and we get the chain rule to give > > [x,y] = T([r,theta]); `g```(u,v) = `f```(x,y)*`T```(u,v); [ x; y ] = [ r cos( ); r sin( ) ] g`( u; v ) = f`( x; y ) T`( u; v ) To get the rst component of , use square brack- in which the lhs is a 1 by 2 matrix and the rhs ets again: is the product of a 1 by 2 matrix and a 2 by 2 > x = T([r,theta])[1]; matrix. x = r cos( ) similarly, Writing the various derivatives in more details > y = T([r,theta])[2]; gives y = r sin( ) > jacobian([g(u,v)],[u,v]) = > > jacobian([f(x,y)],[x,y])* jacobian(T([u,v]),[u,v]); h The Jacobian of the transformation is > 2 3 4 5 T:=U->[x(U[1],U[2]),y(U[1],U[2])]; T := U ! [x (U1 ; U2 ) ; y (U1 ; U2)] Suppose that we are given a scalar function f(x,y) and that, under the transformation, it becomes g(u,v), the composition of f and T. Symbolically, > g(u,v) = '(f@T)'([u,v]); or g( u; v ) = ( f @T )( [ u; v ] ) g( u; v ) h jacobian(T([r,theta]),[r,theta]); cos( ) ,r sin( ) sin( ) r cos( ) Now redene T > @ @u 2 @ @x @ @v f( x; y ) i g( u; v ) = @ @y i x( u; v ) @v@ x( u; v ) y( u; v ) @v@ y( u; v ) Expanding the product on the rhs: @ 4 @u @ @u > > > 3 5 jacobian([g(u,v)],[u,v]) = evalm(jacobian([f(x,y)],[x,y]) &* jacobian(T([u,v]),[u,v])); h i g( u; v ) @v@ g( u; v ) = @ f( x; y ) @ x( u; v ) @x @u @ f( x; y ) @ y( u; v ) ; + @y @u @ @u 21: TRANSFORMING DERIVATIVES 37 @ f( x; y ) @ x( u; v ) @x @v @ f( x; y ) @ y( u; v ) + @y @v Recall that g`( u; v ) = f`( x; y ) T`( u; v ) Thus, provided that the determinant of the jacobian of T is nonzero, f`( x; y ) = g`( u; v ) T`( u; v ),1 where we have grouped all the functions of (x,y) on the left and functions of (u,v) on the right. 2 3 g( r; ) 5 dg := g( r; ) is the transpose of the Jacobian of g(r,theta). @ 4 @r @ @ Then, to solve g`( u; v ) = f`( x; y ) T`( u; v ) for f', we use "linsolve" > > > eq := op(df) = linsolve( transpose(jacobian(T([r,theta]),[r,theta])), dg); 2 3 f eq := 4 x 5 = fy Thus, if T denotes the transformation x = x(u,v), y = y(u,v) and @ , sin( ) @ g( r; ) > g(u,v) = f( x(u,v), y(u,v) ); . g( u; v ) = f( x( u; v ); y( u; v ) ) @ + @r g( r; ) r cos( ) then the relationship we derived above: > `f```(x,y) = `g```(u,v)*`T```(u,v)^`-1`; , 2 2 , 1 r sin( ) + cos( ) f`( x; y ) = g`( u; v ) T`( u; v ) tells us how the x and y derivatives of an arbitrary function f(x,y) may be computed in terms of the derivatives of the transformation T and of @ @ g. r sin( ) @r g( r; ) + @ g( r; ) cos( ) . , , 2 2 For more general transformations from X (with r sin( ) + cos( ) n coordinates) to U (with m coordinates) and The rhs may be simplied; X=T(U), g(U) = (f@T)(U), we have > lhs(eq) = map(simplify,rhs(eq),trig); g`( U ) = f`( X ) T`( U ) from which we can solve for f'(X) only if T' is a 2 3 f square matrix (m=n) and det(T') is not zero. 4 x 5= fy Example: If @ , sin( ) @ g( r; ) > g(r,theta) = f(r*cos(theta),r*sin(theta)); g( r; ) = f( r cos( ); r sin( ) ) @ + @r g( r; ) r cos( ) r show that > > (f[x])^2 + (f[y])^2 = (g[r])^2 + (g[theta])^2/r^2; fx 2 + fy 2 = gr 2 + gr2 2 @ @ r sin( ) @r g( r; ) + @ g( r; ) cos( ) r We dene the transformation > T := U-> [U[1]*cos(U[2]),U[1]*sin(U[2])]; Let > T := U ! [U1 cos (U2 ) ; U1 sin (U2 )] df := matrix(2,1,[f[x], f[y]]); 2 3 f df := 4 x 5 fy which is just a 2 by 1 matrix of names, whereas > We deduce from this the following rules for differentiation wrt x which we express as a function > > Dx := (r,theta,g)-> cos(theta)*diff(g,r) sin(theta)*diff(g,theta)/r; Dx := ( r; ; g ) ! g; ) cos( ) di( g; r ) , sin( ) di( r and, for dierentiation wrt y: dg:=transpose(jacobian([ g(r,theta) ],[r,theta])); 21: TRANSFORMING DERIVATIVES > > Dy := (r,theta,g)-> sin(theta)*diff(g,r) + cos(theta)*diff(g,theta)/r; Dy := ( r; ; g ) ! g; ) sin( ) di( g; r ) + cos( ) di( r These denitions mean that > f[x](x,y) = Dx(r,theta,g(r,theta)); fx ( x; y ) = , @ g( r; ) , sin( ) @@ g( r; ) cos( ) @r r > f[y](x,y) = Dy(r,theta,g(r,theta)); fy ( x; y ) = , @ g( r; ) + cos( ) @@ g( r; ) sin( ) @r r and so > > > eq := fx 2 + fy 2 = , ! , @ g( r; ) , sin( ) @@ g( r; ) cos( ) @r r + cos( ) @@ g( r; ) @ sin( ) @r g( r; ) + r !2 Simplifying the rhs: > lhs(eq) = simplify(rhs(eq), trig); ,@ 2 ,@ 2 2 2 @ @r x y 2 2 g( r; ) f + f = g( r; ) +rr which gives the required relationship. Also, for the second derivatives, > > > eq2 := f[xx] + f[yy] = Dx(r,theta,Dx(r,theta,g(r,theta))) + Dy(r,theta,Dy(r,theta,g(r,theta))); 2 @ eq2 := fxx + fyy = cos( ) cos( ) @r2 g( r; ) , sin( r ) %2 + sin( r2) %1 , sin( ) @ g( r; ) + cos( ) %2 ,sin( ) @r ! 38 sin( ) @2 g( r; ) , cos( r ) %1 , r+ r 2 @ g( r; ) + cos( ) %2 sin( ) sin( ) @r 2 r , cos( r2) %1 + cos( ) @ cos( ) @r g( r; ) + sin( ) %2 2 ! @ g( r; ) cos( ) 2 @ , sin( r ) %1 + r r @ g( r; ) %1 := @ 2 %2 := @@ @r g( r; ) and, simplifying the rhs, > eq := (f[x])^2 + (f[y])^2 = (Dx(r,theta,g(r,theta)))^2 + (Dy(r,theta,g(r,theta)))^2; 2 @2 lhs(eq2) = simplify(rhs(eq2), trig); 2 @ @ fxx + fyy = @r g( r; ) r + @2 g( r; ) 2 @ g( r; ) r2 r2 + @r 2
© Copyright 2026 Paperzz