exam1.mws

Exam 1 MCS 320 Friday 7 October 2005

> restart;

1. Consider the sequence

> restart; u := v; v := w; w := Pi;

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);

v

> eval(u,2); eval(v,1);

w

w

> eval(u,3); eval(v,2); eval(w,1);

Pi

Pi

Pi

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';

w := Pi

v := w

u := v

> eval(u,1); eval(u,2); eval(u,3); # just to verify

v

w

Pi

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));

n := exp(Pi^(1/2))

> f := evalf(n,6);

f := 5.88525

(b) Give a rational approximation for n, accurate up to 6 decimal places.

ANSWER:

> r := convert(f,rational);

r := 23541/4000

> evalf(r); # just to verify

5.885250000

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));

r1 := (x+1)*(x+4)+1/((x+1)*(x+4))

> simplify(r1);

(x^4+10*x^3+33*x^2+40*x+17)/((x+1)*(x+4))

> r2 := numer(r1)/expand(denom(r1));

r2 := (x^4+10*x^3+33*x^2+40*x+17)/(x^2+5*x+4)

 (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));

d := (x+1)*(x+4)

> n := numer(r2);

n := x^4+10*x^3+33*x^2+40*x+17

> q := quo(n,d,x,'rest'); rest;

q := x^2+5*x+4

1

> r3 := factor(q) + rest/d;

r3 := (x+1)*(x+4)+1/((x+1)*(x+4))

4. Do q := (x*y-y)/(x-y); and consider the expression assigned to q.

> q := (x*y - y)/(x-y);

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);

(x*y+y*a)*(x+y*a)^a

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;

p := x^3+4*x+9

(a) Show that p is irreducible over the rational numbers.

ANSWER:

> irreduc(p);

true

(b) Compute a numerical factorization of p.

ANSWER:

> factor(p,complex);

(x+1.464595701)*(x+(-.7322978506+2.368286390*I))*(x+(-.7322978506-2.368286390*I))

(c) Compute a symbolic factorization of p.

ANSWER:

> alias(alpha=RootOf(p)):

> q := evala(p/(x-alpha));

q := x^2+alpha*x+4+alpha^2

> factor(q,alpha); # check if q is irreducible over extension with alpha

x^2+alpha*x+4+alpha^2

> alias(beta=RootOf(q));

alpha, beta

> factor(p,{alpha,beta});

-(x+alpha+beta)*(x-beta)*(-x+alpha)

> evala(AFactor(p));

(x+alpha+beta)*(x-beta)*(x-alpha)

(d) Show how to go from the symbolic to the numerical factorization.

> f := (x-evalf(alpha))*(x-evalf(beta))*(x+evalf(alpha+beta));

f := (x+(-.7322978506-2.368286390*I))*(x+(-.7322978506+2.368286390*I))*(x+(1.464595701+0.*I))

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);

r := (15*z^32-3*z^4+1)/(3*z^24+4*z^8-3)

> cfr := convert(r,confrac,z);

cfr := 5*z^8-20/3/(z^8+3/4-3/20/(z^4+467/36+216145/1296/(z^4-500967067/38906100+16842475584/1167966525625/(z^4+26998004465723/31600841016525+267145142239375/855001518487281/(z^4-27785848/29240409)))))

> cfr1 := algsubs(z^4=y,cfr);

cfr1 := -20/3/(-3/20/(y+467/36+216145/1296/(y-500967067/38906100+16842475584/1167966525625/(y+26998004465723/31600841016525+267145142239375/855001518487281/(y-27785848/29240409))))+y^2+3/4)+5*y^2

> 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;

>