MCS 320 Quiz 3 Friday 9 September 2005
| > | restart; |
1. Type restart; area := Pi*radius^2; radius := 3.4; answer the questions:
(a) Explain the relationship between the variable area, the formula, the variable radius, and the constants Pi and 3.4.
(b) Give the Maple command(s) to show these relationships.
(c) Type restart; radius := 3.4; and complete area := to obtain the same relationships as above.
Answer to 1(a):
| > | restart; area := Pi*radius^2; radius := 3.4; |
The variable area holds the formula to compute the area. The formula to compute the area contains the constant Pi and the variable radius. The variable radius is assigned to the value 3.4.
Answer to 1(b):
| > | eval(area,1); whattype(%); |
| > | eval(area,2); area; |
Answer to 1(c):
| > | restart; radius := 3.4; |
| > | area := Pi*'radius'^2; |
| > | area; |
| > | eval(area,1); |
2. Consider p = 13 x^2 + 1/z + 8. Draw the expression tree for p.
Give all Maple commands (not their output) you used to make your drawing.
Answer:
| > | p := 13*x^2 + 1/z + 8; |
| > | op(p); whattype(p); |
This shows that p is an expression of type + with three operands.
| > | whattype(op(1,p)); op([1,1],p); op([1,2],p); whattype(op([1,2],p)); op([1,2,1],p); op([1,2,2],p); |
The first operand of p is a product with two operands: the constant 13 and the exponent x^2. The exponent is a binary operator with operands x and 2.
| > | op(2,p); whattype(%); op([2,1],p); op([2,2],p); |
We see that 1/z is represented as a z^(-1).
| > | op(3,p); |
The third operand of p is just the constant 8.
The expression tree looks as follows:
+
|---*
| |--- 13
| |--- ^
| |--- x
| |--- 2
|--- ^
| |--- z
| |--- -1
|
|--- 8