2. First Steps in Mupad
Total Page:16
File Type:pdf, Size:1020Kb
2. First Steps in MuPAD Computer algebra systems such as MuPAD are often used interactively. For example, you can enter an instruction to multiply two numbers and wait until MuPAD computes the result and prints it on the screen. After you call the MuPAD program, a session is launched. You find the information how to start the MuPAD program in the MuPAD installation in- structions for your operating system. MuPAD provides a help system which you can consult during a session to find details about system functions, their syntax, their parameters, etc. The following section presents an introduc- tion to MuPAD’s help system. Requesting a help page is probably the most frequently used command for the beginner. The section after that is about using MuPAD as an “intelligent pocket calculator”: calculating with numbers. This is the easiest and the most intuitive part of this tutorial. Afterwards we introduce some system functions for symbolic computations. The corres- ponding section is written quite informally and gives a first insight into the symbolic features of the system. After starting the program, you can enter commands in the MuPAD lan- guage. The system awaits your input when the MuPAD prompt appears on the screen. On a Windows or Macintosh system, the prompt is the • sign, while it is >> on UNIX platforms. We use the UNIX prompt in all examples throughout the book. If you press the <Return> key under UNIX or Windows, this finishes your input and MuPAD evaluates the command that you have entered. Holding <Shift> while pressing <Return> only pro- vokes a linefeed and still leaves MuPAD in input mode. On a Macintosh, <Shift>+<Return> or <Enter> executes a command and <Return> only provokes a linefeed. For all GUI versions, you can exchange the roles of <Return> and <Shift>+<Return> by choosing “Options” in the “View” menu and then clicking on “Enter only.” 82.FirstStepsinMuPAD If you enter: >> sin(3.141) and then press <Return> (or <Enter>, respectively), the result 0.0005926535551 is printed on your screen. The system evaluates the usual sine function at the point 3.141 and returns a floating-point approximation of the value, similar to the output of a pocket calculator. If you terminate your command with a colon, then MuPAD executes the com- mand without printing its result on the screen. This enables you to suppress the output of irrelevant intermediate results. You can enter more than one command in one line. Two subsequent commands have to be separated by a semicolon or a colon, if the result of the first command is to be printed or not, respectively: >> diff(sin(x^2), x); int(%, x) 2 x cos x2 sin x2 Here x^2 denotes the square of x,andtheMuPAD functions diff and int perform the operations “differentiate” and “integrate” (Chapter 7). The char- acter % returns the previous expression (in the example, this is the derivative of sin(x2)). The concept underlying % is discussed in Chapter 12. In the following example, the output of the first command is suppressed by the colon, and only the result of the second command appears on the screen: >> equations := {x+y=1,x-y=1}: >> solve(equations) {[x =1,y =0]} In the previous example, a set of two equations is assigned to the identi- fier equations. The command solve(equations) computes the solution. Chapter 8 discusses the solver in more detail. In the terminal version of MuPAD (on UNIX systems), you can end the current MuPAD session by entering the keyword quit: >> quit 2.1 Explanations and Help 9 MuPAD versions with a graphical interface must be quit with the correspond- ing menu entry in the GUI. 2.1 Explanations and Help If you do not know the correct syntax of a MuPAD command, you can obtain this information directly from the online help system. For many MuPAD routines, the function info returns a brief explanation: >> info(solve) solve -- solve equations and inequalities [try ?solve\ for options] >> info(ln) ln -- the natural logarithm The help page of the corresponding function provides more detailed informa- tion. You can request it by entering help("name"),wherename is the name of the function. The function help expects its argument to be a string, which are generated by double quotes " in MuPAD (Section 4.11). The operator ? is a short form for help. It is used without parenthesis or quotes: >> ?solve The layout of the help pages depends on the MuPAD version. In the following example, you can see a help page in ASCII format, like it is returned by the terminal version of MuPAD in response to ?solve: solve – solve equations and inequalities Introduction solve(eq, x) returns the set of all complex solutions of an equation or inequality eq with respect to x. solve(system, vars) solves a system of equations for the variables vars. solve(eq, vars) is equivalent to solve([eq], vars). solve(system, x) is equivalent to solve(system, [x]). solve(eq) without second argument is equivalent to solve(eq, S) where S is the set of all indeterminates in eq. The same holds for solve(system). 10 2. First Steps in MuPAD Call(s) solve(eq, x <, options>) solve(system, vars <, options>) solve(eq, vars <, options>) solve(system, x <, options>) solve(eq <, options>) solve(system <, options>) solve(ODE) solve(REC) Parameters eq - a single equation or an inequality of type "_equal", "_less", "_leequal",or"_unequal". Also an arithmetical expression is accepted and regarded as an equation with vanishing right hand side. x - the indeterminate to solve for: an identifier or an indexed identifier vars - a non-empty set or list of indeterminates to solve for system - a set, list, array, or table of equations and/or arithmetical expressions. Expressions are regarded as equations with vanishing right hand side. ODE - an ordinary differential equation: an object of type ode. REC - a recurrence equation: an object of type rec. ... We omit the remainder of the output to save space. Figure 2.1 shows a part of the corresponding hypertext document that appears if you have a graphical user interface. The help system is a hypertext system. Active keywords are underlined or framed. If you click on them, you obtain further information about the corresponding notion. The examples in the help pages can be transferred to MuPAD’s input window by clicking on the corresponding underlined or framed prompts. Windows users please use a double-click or drag & drop. Exercise 2.1: Find out how to use MuPAD’s differentiator diff,andcom- pute the fifth derivative of sin(x2). 2.2 Computing with Numbers To compute with numbers, you can use MuPAD like a pocket calculator. The result of the following input is a rational number: >> 1 + 5/2 7 2 2.2 Computing with Numbers 11 Figure 2.1. The help window in MuPAD Pro You see that MuPAD returns exact results (and not rounded floating-point numbers) when computing with integers and rational numbers: >> (1 + (5/2*3))/(1/7 + 7/9)^2 67473 6728 12 2. First Steps in MuPAD The symbol ^ represents exponentiation. MuPAD can compute big numbers efficiently. The length of a number that you may compute is only limited by the available main storage. For example, the 123rd power of 1234 is a fairly big integer:1 >> 1234^123 17051580621272704287505972762062628265430231311106829\ 04705296193221839138348680074713663067170605985726415\ 92314554345900570589670671499709086102539904846514793\ 13561730556366999395010462203568202735575775507008323\ 84441477783960263870670426857004040032870424806396806\ 96865587865016699383883388831980459159942845372414601\ 80942971772610762859524340680101441852976627983806720\ 3562799104 Besides the basic arithmetic functions, MuPAD provides a variety of functions operating on numbers. A simple example is the factorial n!=1· 2 ···n of a nonnegative integer, which can be entered in mathematical notation: >> 100! 93326215443944152681699238856266700490715968264381621\ 46859296389521759999322991560894146397615651828625369\ 7920827223758251185210916864000000000000000000000000 The function isprime checks whether a positive integer is prime. It returns either TRUE or FALSE. >> isprime(123456789) FALSE Using ifactor, you can obtain the prime factorization: >> ifactor(123456789) 32 · 3607 · 3803 2.2.1 Exact Computations √ Now suppose that we want to “compute” the number 56. The problem is that the value of this irrational number cannot be expressed as a quotient numerator/denominator of two integers exactly. Thus “computation” can only mean√ to find an exact representation that is as simple as possible.When you input 56 via sqrt, MuPAD returns the following: 1 In this printout, the “backslash” \ at the end of a line indicates that the result is continued on the next line. 2.2 Computing with Numbers 13 >> sqrt(56) √ 2 14 √ √ √The result of the simplification of 56 is the exact value 2 · 14.InMuPAD, 14 (or, sometimes, 14^(1/2)) represents the positive solution of the equa- 2 tion x =14. Indeed, this√ is probably the most simple representation of the result. We stress that 14 is a genuine MuPAD object with certain proper- ties (e.g., that its square can be simplified to 14). The system applies them automatically when computing with such objects. For example: >> sqrt(14)^4 196 As another example for exact computation, let us determine the limit n 1 e = lim 1+ . n→∞ n We use the function limit and the symbol infinity: >> limit((1 + 1/n)^n, n = infinity) e To enter this number in a MuPAD input, you have to use E or exp(1),where exp represents the exponential function. MuPAD knows exact rules of ma- nipulation for this object. For example, using the natural logarithm ln we find: >> ln(1/exp(1)) −1 We will encounter more exact computations later in this tutorial. 2.2.2 Numerical Approximations Besides exact computations, MuPAD can also perform numerical approxima- tions. For example,√ you can use the MuPAD function float to find a decimal approximation to 56. This function computes the value of its argument in floating-point representation: >> float(sqrt(56)) 7.483314774 14 2.