prac10_online

prac10_online - Practical 0: Maple Refresher Start by...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 2010-11-08 Floating-point 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 floating-point 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 floating-point number): xx := evalf(exp(1),4); evalf(xx - 2.718, 100); here xx is really 2 . 718000 negationslash = e. The built-in variable Digits controls the precision of (most) floating-point 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 2010-11-08 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.

Page1 / 13

prac10_online - Practical 0: Maple Refresher Start by...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online