exam2.mws

MCS 320 Exam 2 Friday 4 November 2005

> restart;

1. Give the Maple commands to

(a) Generate a sequence s of 100 numbers using the formula 1/(k*(k+1)).

(b) Use s to create a new sequence S.  The k-th element of S is the sum of the first k elements of s.

(c) Show that the sum of the n elements in s equals n/(n+1).

ANSWER to (a):

> s := seq(1/(k*(k+1)),k=1..100);

s := 1/2, 1/6, 1/12, 1/20, 1/30, 1/42, 1/56, 1/72, 1/90, 1/110, 1/132, 1/156, 1/182, 1/210, 1/240, 1/272, 1/306, 1/342, 1/380, 1/420, 1/462, 1/506, 1/552, 1/600, 1/650, 1/702, 1/756, 1/812, 1/870, 1/9...s := 1/2, 1/6, 1/12, 1/20, 1/30, 1/42, 1/56, 1/72, 1/90, 1/110, 1/132, 1/156, 1/182, 1/210, 1/240, 1/272, 1/306, 1/342, 1/380, 1/420, 1/462, 1/506, 1/552, 1/600, 1/650, 1/702, 1/756, 1/812, 1/870, 1/9...s := 1/2, 1/6, 1/12, 1/20, 1/30, 1/42, 1/56, 1/72, 1/90, 1/110, 1/132, 1/156, 1/182, 1/210, 1/240, 1/272, 1/306, 1/342, 1/380, 1/420, 1/462, 1/506, 1/552, 1/600, 1/650, 1/702, 1/756, 1/812, 1/870, 1/9...s := 1/2, 1/6, 1/12, 1/20, 1/30, 1/42, 1/56, 1/72, 1/90, 1/110, 1/132, 1/156, 1/182, 1/210, 1/240, 1/272, 1/306, 1/342, 1/380, 1/420, 1/462, 1/506, 1/552, 1/600, 1/650, 1/702, 1/756, 1/812, 1/870, 1/9...s := 1/2, 1/6, 1/12, 1/20, 1/30, 1/42, 1/56, 1/72, 1/90, 1/110, 1/132, 1/156, 1/182, 1/210, 1/240, 1/272, 1/306, 1/342, 1/380, 1/420, 1/462, 1/506, 1/552, 1/600, 1/650, 1/702, 1/756, 1/812, 1/870, 1/9...s := 1/2, 1/6, 1/12, 1/20, 1/30, 1/42, 1/56, 1/72, 1/90, 1/110, 1/132, 1/156, 1/182, 1/210, 1/240, 1/272, 1/306, 1/342, 1/380, 1/420, 1/462, 1/506, 1/552, 1/600, 1/650, 1/702, 1/756, 1/812, 1/870, 1/9...

ANSWER to (b):

> seq(sum(s[k],k=1..n),n=1..100);

1/2, 2/3, 3/4, 4/5, 5/6, 6/7, 7/8, 8/9, 9/10, 10/11, 11/12, 12/13, 13/14, 14/15, 15/16, 16/17, 17/18, 18/19, 19/20, 20/21, 21/22, 22/23, 23/24, 24/25, 25/26, 26/27, 27/28, 28/29, 29/30, 30/31, 31/32, ...1/2, 2/3, 3/4, 4/5, 5/6, 6/7, 7/8, 8/9, 9/10, 10/11, 11/12, 12/13, 13/14, 14/15, 15/16, 16/17, 17/18, 18/19, 19/20, 20/21, 21/22, 22/23, 23/24, 24/25, 25/26, 26/27, 27/28, 28/29, 29/30, 30/31, 31/32, ...1/2, 2/3, 3/4, 4/5, 5/6, 6/7, 7/8, 8/9, 9/10, 10/11, 11/12, 12/13, 13/14, 14/15, 15/16, 16/17, 17/18, 18/19, 19/20, 20/21, 21/22, 22/23, 23/24, 24/25, 25/26, 26/27, 27/28, 28/29, 29/30, 30/31, 31/32, ...1/2, 2/3, 3/4, 4/5, 5/6, 6/7, 7/8, 8/9, 9/10, 10/11, 11/12, 12/13, 13/14, 14/15, 15/16, 16/17, 17/18, 18/19, 19/20, 20/21, 21/22, 22/23, 23/24, 24/25, 25/26, 26/27, 27/28, 28/29, 29/30, 30/31, 31/32, ...1/2, 2/3, 3/4, 4/5, 5/6, 6/7, 7/8, 8/9, 9/10, 10/11, 11/12, 12/13, 13/14, 14/15, 15/16, 16/17, 17/18, 18/19, 19/20, 20/21, 21/22, 22/23, 23/24, 24/25, 25/26, 26/27, 27/28, 28/29, 29/30, 30/31, 31/32, ...

ANSWER to (c):

> normal(sum(1/(k*(k+1)),k=1..n));

n/(n+1)

2. (a) Give an example illustrating the conversion of a formula into a function.

   (b) Give an example illustrating the conversion of a function into a formula.

ANSWER to (a):

> p := x+1: f := unapply(p,x);

f := proc (x) options operator, arrow; x+1 end proc

ANSWER to (b):

> q := f(z); # evaluate function at a symbol

q := z+1

3. Consider a procedure nH which returns the nested Horner form of a polynomial.  

The argument of the procedure is the variable of the polynomial.

The coefficients of the polynomial are given by a sequence as an index to the procedure,

for example: nH[a3,a2,a1,a0](x) = a0 + x*(a1 + x*(a2 + a3*x)).

Observe that nH[a0](x) = a0 and nH[a3,a2,a1,a0](x) = a0 + x*nH[a3,a2,a1](x).

(a) Use these observations to write a recursive procedure to implement nH.

    For simplicity, assume there is always at least one element in the index sequence to nH.

   Write your implementation of nH so that Maple remembers the result of all calls made to nH.

(b) Execute nH[a,b,c,d](x).  Give the Maple command(s) to know what nH[a,b,c](x) is without calling nH again.

ANSWER to (a):

> nH := proc(x)
 description `nested Horner's rule`:

 option remember:

 local a,n:

 a := op(procname):

 n := nops([a]):

 if n = 1 then

   return a:

 else

   return a[n] + x*nH[a[1..n-1]](x);

 end if;

end proc:

ANSWER to (b):

> nH[a,b,c,d](x);

d+x*(c+x*(b+x*a))

> T := op(4,eval(nH));

T := TABLE([(a, b)::(x) = b+x*a, (a, b, c)::(x) = c+x*(b+x*a), (a, b, c, d)::(x) = d+x*(c+x*(b+x*a)), (a)::(x) = a])

4. (a) Explain the difference between automatic and symbolic differentiation.

        Give the Maple commands for both types of differentiation.

   (b) When is automatic differentiation better than symbolic differentiation?

         Give an example and explain why automatic differentiation is preferred.

ANSWER to (a):

Automatic differentiation is the derivation of programs, done in Maple by the command D.

Symbolic differentiation is the derivation of formulas, done by the command diff.

ANSWER to (b):

Symbolic differentiation may lead to expression swell.

Example:

> f := z -> z^2+1; f10 := f@@10; D(f10);

f := proc (z) options operator, arrow; z^2+1 end proc

f10 := `@@`(f, 10)

`@`(proc (z) options operator, arrow; 2*z end proc, `@@`(f, 9))*`@`(proc (z) options operator, arrow; 2*z end proc, `@@`(f, 8))*`@`(proc (z) options operator, arrow; 2*z end proc, `@@`(f, 7))*`@`(proc...`@`(proc (z) options operator, arrow; 2*z end proc, `@@`(f, 9))*`@`(proc (z) options operator, arrow; 2*z end proc, `@@`(f, 8))*`@`(proc (z) options operator, arrow; 2*z end proc, `@@`(f, 7))*`@`(proc...

5. Find the number of extremal values of f(x,y) = 3*x*y + y^2 + 6 for points satisfying g(x,y) = x^2 + y^2 -1 = 0.

It suffices to find only the number of candidate extrema, not their actual values.

Give all relevant Maple commands you used.  Jusfify your final answer.

Note that it suffices to find the number of candidate extrema, not their actual values.

ANSWER :

> f := 3*x*y + y^2 + 6; g := x^2 + y^2 - 1;

f := 3*x*y+y^2+6

g := x^2+y^2-1

> s := [diff(f,x) - lambda*diff(g,x),diff(f,y) - lambda*diff(f,y),g];

s := [3*y-2*lambda*x, 3*x+2*y-lambda*(3*x+2*y), x^2+y^2-1]

> gb := grobner[gbasis](s,[x,y,lambda],plex);

gb := [6*x-5*y-4*lambda*y, 169*y^2+20*lambda-72, -9+5*lambda+4*lambda^2]

There are four candidate extremal values.  Justification: there are two values for lambda, and since the degree of y is two in gb[2], for every value of lambda we have two values of y.  Because the degree of x is 1 in gb[1], we have one value for x for every value of y, so in total we have four solutions.

5. Consider the curve defined by p(x,y) = x^3 - y^2 = 0.  Give all commands to

(a) make a plot of p for x and y both in the interval [-2,+2];

(b) convert p into polar coordinates (give the final result too);

(c) plot the curve in polar coordinates, using the right range for t.

ANSWER to (a):

> p := x^3 - y^2;

p := x^3-y^2

> plots[implicitplot](p,x=-2..2,y=-2..2,numpoints=1000);

[Plot]

ANSWER to (b):

> pp := subs(x=r*cos(t),y=r*sin(t),p);

pp := r^3*cos(t)^3-r^2*sin(t)^2

> s := solve(pp/r^2,r);

s := sin(t)^2/cos(t)^3

ANSWER to (c):

> plots[polarplot](s,t=-1..1);

[Plot]

7. Consider the initial value problem dy/dt - 3 y = e^t, with y(0) = A and y'(0) = B.

(a) Give the Maple command(s) to define this problem.

(b) Give the Maple command(s) to compute a series solution with error O(t^4).

ANSWER to (a):

> ivp := {diff(y(t),t$2) - 3*y(t) = exp(t),y(0) = A,D(y)(0)=B};

ivp := {diff(y(t), `$`(t, 2))-3*y(t) = exp(t), y(0) = A, D(y)(0) = B}

ANSWER to (b):

> dsolve(ivp,y(t),series,order=4);

y(t) = series(A+B*t+(3/2*A+1/2)*t^2+(1/2*B+1/6)*t^3+O(t^4),t,4)