Exam 1 MCS 320 Friday 7 October 2005
| > | restart; |
1. Consider the sequence
| > | restart; u := v; v := w; w := Pi; |
(a) Draw three pictures, one after each assignment, to illustrate the links between the variables.
ANSWER:
after u := v; we have u -> v
after v := w; we have u -> v -> w
after w := Pi; we have u -> v -> w -> Pi
(b) Give the Maple commands to verify the links between the variables.
| > | eval(u,1); |
| > | eval(u,2); eval(v,1); |
| > | eval(u,3); eval(v,2); eval(w,1); |
ANSWER:
(c) Complete the sequence restart; w := Pi; with the appropriate Maple command(s) to establish the same dependencies between the variables as the ones established by the sequence above.
| > | restart; w := Pi; v := 'w'; u := 'v'; |
| > | eval(u,1); eval(u,2); eval(u,3); # just to verify |
ANSWER:
2. Consider the number n = exp(sqrt(Pi)).
(a) Give a numerical approximation of n with 6 decimal places.
ANSWER:
| > | n := exp(sqrt(Pi)); |
| > | f := evalf(n,6); |
(b) Give a rational approximation for n, accurate up to 6 decimal places.
ANSWER:
| > | r := convert(f,rational); |
| > | evalf(r); # just to verify |
3(a) Give the Maple commands to transform (x+1)(x+4) + 1/((x+1)(x+4)) into (x^4 + 10x^3 + 33x^2 + 40x + 17)/(x^2 + 5x + 4).
ANSWER:
| > | restart; |
| > | r1 := (x+1)*(x+4) + 1/((x+1)*(x+4)); |
| > | simplify(r1); |
| > | r2 := numer(r1)/expand(denom(r1)); |
(b) Give the Maple commands to transform (x^4 + 10x^3 + 33x^2 + 40x + 17)/(x^2 + 5x + 4) into (x+1)(x+4) + 1/((x+1)(x+4)).
ANSWER:
| > | d := factor(denom(r2)); |
| > | n := numer(r2); |
| > | q := quo(n,d,x,'rest'); rest; |
| > | r3 := factor(q) + rest/d; |
4. Do q := (x*y-y)/(x-y); and consider the expression assigned to q.
| > | q := (x*y - y)/(x-y); |
(a) Give the Maple command(s) (not the output!) to display the internal representation of this expression.
ANSWER:
| > | dismantle(q); |
PROD(5)
SUM(5)
PROD(5)
NAME(4): x
INTPOS(2): 1
NAME(4): y
INTPOS(2): 1
INTPOS(2): 1
NAME(4): y
INTNEG(2): -1
INTPOS(2): 1
SUM(5)
NAME(4): x
INTPOS(2): 1
NAME(4): y
INTNEG(2): -1
INTNEG(2): -1
(b) Draw the directed acyclic graph which represents this expression.
ANSWER: see the answer sheet.
(c) Explain the output of subs(-1=a,q). Be complete in your explanation.
ANSWER:
| > | subs(-1=a,q); |
Every object is stored only once in Maple. The division is represented by a negative power, i.e.: as (x*y-y)*(x-y)^(-1). So we see three times -1 replaced by a. We also notice the order y*a, because the -y is stored as y*(-1).
5. Consider the polynomial p = x^3 + 4x + 9.
| > | p := x^3 + 4*x + 9; |
(a) Show that p is irreducible over the rational numbers.
ANSWER:
| > | irreduc(p); |
(b) Compute a numerical factorization of p.
ANSWER:
| > | factor(p,complex); |
(c) Compute a symbolic factorization of p.
ANSWER:
| > | alias(alpha=RootOf(p)): |
| > | q := evala(p/(x-alpha)); |
| > | factor(q,alpha); # check if q is irreducible over extension with alpha |
| > | alias(beta=RootOf(q)); |
| > | factor(p,{alpha,beta}); |
| > | evala(AFactor(p)); |
(d) Show how to go from the symbolic to the numerical factorization.
| > | f := (x-evalf(alpha))*(x-evalf(beta))*(x+evalf(alpha+beta)); |
6. Consider r = (15*z^(32) - 3*z^4 + 1)/(3*z^24 + 4*z^8-3). What is the most efficient way to evaluate r?
Give all Maple commands and their output in your answer.
ANSWER:
| > | r := (15*z^(32) - 3*z^4 + 1)/(3*z^24 + 4*z^8-3); |
| > | cfr := convert(r,confrac,z); |
| > | cfr1 := algsubs(z^4=y,cfr); |
| > | codegen[C](cfr1,optimized); |
t13 = y*y;
t18 = -20.0/3.0/(-3.0/20.0/(y+467.0/36.0+216145.0/1296.0/(y-500967067.0/
38906100.0+16842475584.0/1167966525625.0/(y+26998004465723.0/31600841016525.0+
267145142239375.0/855001518487281.0/(y-27785848.0/29240409.0))))+t13+3.0/4.0)+
5.0*t13;
| > |