This preview shows pages 1–4. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Practical 0: Maple Refresher Start by launching Maple: Start Programs Programming Languages Maple 12 Maple 12 While youre at it, drag the icon to your desktop for later use. Before you start , the following setup will make it easier to see what you are doing and spot typos: Tools Options Display Input display Maple Notation Tools Options Interface Default format for new worksheets Worksheet Click on Apply globally when done. The input you type should now appear in red . Use the icon in the toolbar to open a new file. Please type in the examples exactly as shown, paying attention to Capital Letters and punctuation, and proceed only after you have understood the output. Assignment and Variables It is useful to think of variables in Maple as containers where values (numbers, vectors, or more complex objects) may be stored. The symbol := is an assignment , not equality; x := sin(Pi/4); roughly means: compute sin / 4 and put the result in the variable (container) x . Although x = x + 1 is clearly nonsense, the statement x := x + 1; makes perfect sense in Maple: it increases the value of x by one. Control statements Figure out what this does: mysum := 0; for n from 0 to 10 do mysum := mysum + n^2; end do; mysum; Use similar constructs to compute 0.1 100! = producttext 100 n =1 n , 0.2 T 10 where T 1 = 1 and T n +1 = T 2 n + 1. Hint: write the last two computations in this notation. MATH2051 Practical 1 20101108 Floatingpoint Operations Numbers written with a decimal point are treated as floating point numbers, meaning (roughly) that they have a finite precision. 0.3 In Maple, 1.2 (a floatingpoint number) is a different type of object from 6/5 (an exact expression). Explain the result of: x := 1.2; z := x + 10^(12); 10^12*(z  1.2); y := 6/5; w := y + 10^(12); 10^12*(w  6/5); One uses evalf to obtain numerical approximations (i.e. to convert an expression into a floatingpoint number): xx := evalf(exp(1),4); evalf(xx  2.718, 100); here xx is really 2 . 718000 negationslash = e. The builtin variable Digits controls the precision of (most) floatingpoint operations: Digits := 3; 1 + 0.0001; The default value is 10. 0.4 Explain the difference between x:=exp(1) and y:=exp(1.0) . Hint: use evalf . 0.5 Set Digits:=20 and redo 3 above. Plotting Some examples [type, e.g., ?unassign to get help]: unassign(x); plot( sin(x), x=0..3 ); plot( [exp(x),exp(x^2)], x=1..1, colour=[red,blue] ); Functions To define simple functions, we use the mapping notation: f := x > x^2; f(5); MATH2051 Practical 2 20101108 More complicated functions can be defined using the proc construct: Arctan2 := proc(y,x) a := arctan(y/x); if( x < 0 ) then a := a + evalf(Pi); end if; if( a > evalf(Pi) ) then a := a  2*evalf(Pi); end if; return a; end; Arctan2(2.0,1.0); Arctan2(2.0,1.0); All variables inside a function are local , in the sense that they have nothing to do with variables outside with the same name.variables outside with the same name....
View
Full
Document
This note was uploaded on 02/09/2011 for the course MATH 2051 taught by Professor Dr.a.wacher during the Fall '11 term at Durham.
 Fall '11
 Dr.A.Wacher
 Numerical Analysis

Click to edit the document details