Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
MA310 MAPLE — Example Sheet 1 Maple is a comprehensive Symbolic Computation System or Computer Algebra System for advanced Mathematics. These phrases refer to Maple’s capability to manipulate information in a symbolic or algebraic manner. Conventional mathematical programs require numerical values for all variables whilst Maple maintains and manipulates the underlying symbols and expressions. Maple includes facilities for interactive algebra, calculus, discrete Mathematics, differential equations, graphics, numerical computation and many other areas of Mathematics. Maple 10 is available on the windows system under Central Software. You should also be able to get a copy for your own computer from Computing Services. The first time you start Maple 10, please make the following configuration changes: 1. Under Tools > Options > Display set Input display to Maple notation and then Apply Globally; 2. Under Tools > Options > Interface set Default format for new worksheets to Worksheet and then Apply Globally. You may need to restart Maple for these changes to take effect. Maple Basics — Arithmetic operations in Maple Operation addition subtraction multiplication division exponentiation factorial Symbol Example Maple Command + 2+2 2+2 10 − x 10-x * 3xy 3*x*y / a ÷ b or a/b a/b 2 ^ or ** x x^2 or x**2 ! 20! 20! Remarks • Maple command lines will be given as lines beginning with the symbol >, e.g. > x+y; x+y • To add, subtract, multiply or divide integers, fractions, polynomials or rational functions, type in the expression you wish to compute. Then you end the expression with a semi-colon “;”, followed by pressing the RETURN key (<cr>). You should put a semi-colon or colon at the end of a command. A semi-colon causes the command to be executed and the result to be displayed. A colon causes the command to be executed but the result is not displayed. • New Maple users sometimes type 2 x, 2x or x2 when they mean “multiply 2 and x together”, i.e. 2 × x. Spaces between symbols are optional, but Maple requires * for multiplication, i.e. one types 2*x or x*2. • Round brackets are used to indicate precedence, so 2*(3+5) evaluates to 16. Also, since the multiplication symbol can not be suppressed, 2(3+5) and 2*(3+5) do not produce the same Maple output. Examples > (2+3)*7; 35 > 1/35; 1 35 > 1/35.0; .02857142857 > > 2^(1/2); √ 2 2^(.5); 1.414213562 > > a/(b-c); a b−c (x+2*y); x + 2y • The percentage symbol “%”, known as the ditto operator , is used as a name for the previous successfully executed result. Maple applies the new command to this expression. You can also use your mouse to cut and paste and you can go back, edit a line and then re-execute. > %^5; (x + 2 y)5 • The Maple commands such as expand and factor can be used to manipulate algebraic expressions: expand multiplies out expressions in full and factor finds the polynomial factors. > expand(%); x5 + 10 x4 y + 40 x3 y 2 + 80 x2 y 3 + 80 x y 4 + 32 y 5 > factor(%); (x + 2 y)5 > 20!; 2432902008176640000 > %/18!; 380 > y:=t^2-5*t+6; y := t2 − 5 t + 6 > solve(y=0,{t}); {t = 2}, {t = 3} • The command evalf stands for ‘evaluate using floating-point arithmetic’. > evalf(4/7); .5714285714 > evalf(4/7,20); .57142857142857142857 > > sqrt(3); √ 3 evalf(%); 1.732050808 > y:=2*x-3; y := 2 x − 3 > y^2+8*y+7; (2 x − 3)2 + 16 x − 17 > expand(%); 4 x2 + 4 x − 8 > factor(%); 4 (x + 2) (x − 1) Getting Help: Maple commands are documented in the online help facility. Spend some time exploring the help available. Often the most informative section of a help file is the Examples section which illustrates the use of the command. Graphics Maple can help you can visualise mathematics. Frequently one of the best ways of understanding a mathematical structure is to plot it in an appropriate way. Maple can produce several forms of plots, many of which we shall meet during this course. Two of the most versatile commands for plotting mathematical functions are plot, for two-dimensional functions and plot3d, for three-dimensional functions. sin(x) For our first example, we plot f (x) = for −10 ≤ x ≤ 10. x > plot(sin(x)/x,x=-10..10); Our second example is a 3D plot: f (x, y) = sin(x) cos(y) for 0 ≤ x ≤ 4π and 0 ≤ y ≤ 4π. > plot3d(sin(x)*cos(y),x=0..4*Pi,y=0..4*Pi); Exercises 1. Use Maple to execute the following commands: > 100!; > %/(99!); > 2/3 + 7/8; > (a+b)^10; > expand(%); > factor(%); > expand((x+y)^3)/(x+y); 2. Experiment with Maple using the following commands: > restart; > x^12; > 3/11; > %^12; > y; > y := t^2 + 3*t -2; > answer := solve(y=0,t); > > > > answer[1]; evalf(%); y := ’y’; y; • The command restart restores Maple to its initial state. • The assignment := makes y the name of the expression t2 + 3t − 2. • The current value of y is given by the command y;. • There is a solve command that can be used to solve exactly a large variety of equations, systems of equations and inequalities. • An individual name such as y can be “unassigned” by assigning it to itself in quotes as a value, as in ’y’. The single quotes prevent evaluation. 3. The evalf command is used to produce decimal expansions of numbers. Compare the decimal expansions of the following two expressions. Can you see a repeating pattern? What does the presence or absence of a repeating pattern tell you about a number? > sqrt(2); > evalf(sqrt(2)); > evalf(sqrt(2),40); > Pi; > evalf(Pi); > evalf(Pi,40); > 5/17; > evalf(5/17); > evalf(5/17,40); √ • The special numbers 2 and π are represented by sqrt(2) and Pi, respectively. • The Maple command pi gives the greek letter π rather than the number π. This can be seen by as follows: > evalf(pi); π • The results of the evalf command usually have decimal points. • Maple ordinarily gives you ten digits of precision. To extend this, specify the required precision as part of the evalf command. 4. Plot the following functions (i) f (x) = 7 sin(x) + sin(7x), for 0 ≤ x ≤ 10, √ sin(r) (ii) f (x, y) = , where r = x2 + y 2 , for −20 ≤ x ≤ 20 and −20 ≤ y ≤ 20. r Basic Expression Manipulation Maple tends to perform very little simplification of expressions as they are entered. The way in which an expression is to be manipulated is essentially left to the user. The most elementary functions which can be applied to an expression are: expand(expr), factor(expr), normal(expr), collect(expr,x), convert(expr,parfrac,x), simplify(expr), numer(expr) and denom(expr), which are briefly described in the following table. Maple Command expand(expr) factor(expr) normal(expr) collect(expr,x) convert(expr,parfrac,x) simplify(expr) numer(expr) denom(expr) Meaning multiplies all the factors in the expression expr is used to factor the expression expr converts the expression expr into rational form collects all coefficients of powers of x in the expression expr expresses the expression expr in partial fraction of x applies a number of simplification rules to the expression expr gives the numerator of the rational expression expr gives the denominator of the rational expression expr Examples Example 1. Determine the partial fraction decomposition of the function > 1 . (x − 3)(x − 1) convert(1/((x-3)*(x-1)),parfrac,x); 1 1 1 1 − 2x−3 2x−1 Example 2. Apply the factor, normal, simplify commands to the expression Express this in partial fractions. > f:=(x^2-1)/(x^2-2*x+1)^2; f := > x2 − 1 (x2 − 2x + 1)2 factor(f); x+1 (x − 1)3 > normal(f); x+1 (x − 1)(x2 − 2x + 1) > simplify(f); x+1 (x − 1)(x2 − 2x + 1) x2 − 1 . (x2 − 2x + 1)2 > convert(f,parfrac,x); 2 1 + 3 (x − 1) (x − 1)2 Example 3. Apply the simplify command to ln(2x ) and exp(3 ln x). > simplify(ln(2**x)); x ln(2) > simplify(exp(3*ln(x))); x3 Example 4. Apply the collect command to collect the coefficients of powers of x in g = (x + 4y)3 + 2x − 3y 2 . f = (x + 1)(x + 2), Collect the coefficients of powers of y in g. > f:=(x+1)*(x+2); f := (x + 1)(x + 2) > collect(f,x); x2 + 3x + 2 > > > g:=(x+4*y)**3+2*x-3*y**2; g := (x + 4y)3 + 2x − 3y 2 collect(g,x); x3 + 12yx2 + (2 + 48y 2 )x + 64y 3 − 3y 2 collect(g,y); 64y 3 + (48x − 3)y 2 x + 12yx2 + x3 + 2x x2 + 3x + 2 . Extract the numerator x2 + 5x + 6 and denominator of y and factor them. Apply the normal command to y and then extract the numerator and denominator of the resulting expression. Example 5. Consider the rational function y = > y:=(x^2+3*x+2)/(x^2+5*x+6); y := > x2 + 3x + 2 x2 + 5x + 6 numer(y); x2 + 3x + 2 > factor(%); (x + 1)(x + 2) > denom(y); x2 + 5x + 6 > factor(%); (x + 3)(x + 2) > z:=normal(y); z := > x+1 x+3 numer(z); x+1 > denom(z); x+3 Remarks • The normal command is a basic form of simplification. It recognises those expressions equal to zero which lie in the domain of “rational functions”. This includes any expression constructed from sums, products and integer powers of integers and variables. The expression is converted into the form numerator/denominator, where the numerator and denominator are relatively prime polynomials with integer coefficients. • The simplify command is a more powerful simplification tool which also applies to more general expressions involving square roots, trigonometric, exponential and logarithmic functions etc., as well as rational functions. • The exponential function ex or exp(x) is written as exp(x) in Maple. The logarithmic function ln x or log x (assumed to be to base e) is written as ln(x) or log(x) in Maple. • The procedures numer and denom are typically called after first using the normal command. The procedure normal is used to put an expression in “normal form” which is the form numerator/denominator where both the numerator and denominator are polynomials. In this case, numer simply picks off the numerator of the expression and denom picks off the denominator of the expression (see Example 5). Exercises 5. Use Maple help to get more information about the Maple commands expand, factor, normal, collect, convert, simplify, numer and denom. 6. Write in Maple each of the following expressions 1 5 + , x − 2 3x x−2 , 4 x − 3x3 + 1 (x2 + 1)(x − 4)3 , (x2 − 2x − 7)3 xy+1 , √ π, ln(x2 + 1), 2 exy . x12 − 1 7. Apply the factor, normal and simplify commands to the expression 4 . (x − 1)2 Express this in partial fractions. 8. Use the collect command to collect the coefficients of powers of x in f = (x + 1)(x + 2)2 (x2 + 3)(5x − 4)3 , g = (x + 2y + 3z 2 )2 + (x + y 3 )5 . Collect the coefficients of powers of y and z in g. x3 + x2 − 2x − 2 . Extract the numerator and x3 + x2 − 4x − 4 denominator of y and factor them. Apply the normal command to y and then extract the numerator and denominator of the resulting expression. 9. Consider the rational function y = 10. Apply the factor command to x2 + 1. Are you satisfied by the result? Let √ i = −1. Is x − i a factor of x2 + 1. Look through the help for factor. Can you get Maple to produce an interesting factorisation of x2 + 1? How many factors does x3 − 1 have? 11. Apply factor to 18. Are you satisfied by the result? The number 18 can be factored over the integers as 2(32 ). Look through the help for factor. Can you get Maple to factor the integer 18? List the common factors of 210 − 1 and 215 − 1. 12. Explore Maple’s New User’s Tour. Under Help, select Introduction. You then have a choice of the Quick New User’s Tour or the full New User’s Tour. 13. Challenging Exercise Consider the rational expression form the expression into the following forms: (a) (c) (e) x2 − 4 , x2 − 1 x2 4 − 2 , 2 x −1 x −1 (x − 2)(x + 2)(x + 1) , x3 + x2 − x − 1 1 November 2007 x4 + x3 − 4x2 − 4x . Transx4 + x3 − x2 − x (x − 2)(x + 2) , (x − 1)(x + 1) x2 4 (d) − (x − 1)(x + 1) (x − 1)(x + 1) x4 + x3 − 4x2 − 4x (f) x(x − 1)(x + 1)2 (b)