quiz6.mws

MCS 320 Quiz 6 Friday 30 September 2006

> restart;

1. Define the following function

                  {    1     if x < -1

         f(x) = {  x^2   if x >=1 and x <= 2

                  {     4    if x > 2.
   Illustrate your definition by computing the derivative of f, i.e. give the output of the command diff(f,x).

ANSWER :

> f := piecewise(x<-1,1,x>2,4,x^2);

f := PIECEWISE([1, x < -1], [4, 2 < x], [x^2, otherwise])

> diff(f,x);

PIECEWISE([0, x < -1], [undefined, x = -1], [2*x, x < 2], [undefined, x = 2], [0, 2 < x])

2. Write an efficient recursive procedure to compute polynomials p(x) defined by

      p[0](x) = 5, p[1](x) = 1 - x, p[n] = (x-1)*p[n-1](x) + p[n-2](x-1), for n > 1.

   The degree of the polynomial must be used as an index.

   The argument of the procedure is x.

   The procedure should return an expanded polynomial.

   What is the coefficient of x^50 in p[50](x)?

ANSWER :

> p := proc(x)

>   option remember;

>   local n:
  n := op(procname):

  if n = 0 then

     return 5;

  elif n = 1 then

     return 1 - x;

  else

     return expand((x-1)*p[n-1](x) + p[n-2](x-1));

  end if;

end proc;

p := proc (x) local n; option remember; n := op(procname); if n = 0 then return 5 elif n = 1 then return 1-x else return expand((x-1)*p[n-1](x)+p[n-2](x-1)) end if end procp := proc (x) local n; option remember; n := op(procname); if n = 0 then return 5 elif n = 1 then return 1-x else return expand((x-1)*p[n-1](x)+p[n-2](x-1)) end if end procp := proc (x) local n; option remember; n := op(procname); if n = 0 then return 5 elif n = 1 then return 1-x else return expand((x-1)*p[n-1](x)+p[n-2](x-1)) end if end procp := proc (x) local n; option remember; n := op(procname); if n = 0 then return 5 elif n = 1 then return 1-x else return expand((x-1)*p[n-1](x)+p[n-2](x-1)) end if end procp := proc (x) local n; option remember; n := op(procname); if n = 0 then return 5 elif n = 1 then return 1-x else return expand((x-1)*p[n-1](x)+p[n-2](x-1)) end if end procp := proc (x) local n; option remember; n := op(procname); if n = 0 then return 5 elif n = 1 then return 1-x else return expand((x-1)*p[n-1](x)+p[n-2](x-1)) end if end proc

> p[0](z); p[1](z); p[2](z);

5

1-z

2*z-z^2+4

> p[50](z);

-z^50+50*z^49-7608320154970245572376292980809948*z^14+10811254645381146528120022396491916044*z^3-11913615159357772540551773897287138656*z^4+6051956607854123248198916*z^27+1109882664*z^43-7337264179461...-z^50+50*z^49-7608320154970245572376292980809948*z^14+10811254645381146528120022396491916044*z^3-11913615159357772540551773897287138656*z^4+6051956607854123248198916*z^27+1109882664*z^43-7337264179461...-z^50+50*z^49-7608320154970245572376292980809948*z^14+10811254645381146528120022396491916044*z^3-11913615159357772540551773897287138656*z^4+6051956607854123248198916*z^27+1109882664*z^43-7337264179461...-z^50+50*z^49-7608320154970245572376292980809948*z^14+10811254645381146528120022396491916044*z^3-11913615159357772540551773897287138656*z^4+6051956607854123248198916*z^27+1109882664*z^43-7337264179461...-z^50+50*z^49-7608320154970245572376292980809948*z^14+10811254645381146528120022396491916044*z^3-11913615159357772540551773897287138656*z^4+6051956607854123248198916*z^27+1109882664*z^43-7337264179461...-z^50+50*z^49-7608320154970245572376292980809948*z^14+10811254645381146528120022396491916044*z^3-11913615159357772540551773897287138656*z^4+6051956607854123248198916*z^27+1109882664*z^43-7337264179461...-z^50+50*z^49-7608320154970245572376292980809948*z^14+10811254645381146528120022396491916044*z^3-11913615159357772540551773897287138656*z^4+6051956607854123248198916*z^27+1109882664*z^43-7337264179461...-z^50+50*z^49-7608320154970245572376292980809948*z^14+10811254645381146528120022396491916044*z^3-11913615159357772540551773897287138656*z^4+6051956607854123248198916*z^27+1109882664*z^43-7337264179461...-z^50+50*z^49-7608320154970245572376292980809948*z^14+10811254645381146528120022396491916044*z^3-11913615159357772540551773897287138656*z^4+6051956607854123248198916*z^27+1109882664*z^43-7337264179461...-z^50+50*z^49-7608320154970245572376292980809948*z^14+10811254645381146528120022396491916044*z^3-11913615159357772540551773897287138656*z^4+6051956607854123248198916*z^27+1109882664*z^43-7337264179461...-z^50+50*z^49-7608320154970245572376292980809948*z^14+10811254645381146528120022396491916044*z^3-11913615159357772540551773897287138656*z^4+6051956607854123248198916*z^27+1109882664*z^43-7337264179461...-z^50+50*z^49-7608320154970245572376292980809948*z^14+10811254645381146528120022396491916044*z^3-11913615159357772540551773897287138656*z^4+6051956607854123248198916*z^27+1109882664*z^43-7337264179461...-z^50+50*z^49-7608320154970245572376292980809948*z^14+10811254645381146528120022396491916044*z^3-11913615159357772540551773897287138656*z^4+6051956607854123248198916*z^27+1109882664*z^43-7337264179461...-z^50+50*z^49-7608320154970245572376292980809948*z^14+10811254645381146528120022396491916044*z^3-11913615159357772540551773897287138656*z^4+6051956607854123248198916*z^27+1109882664*z^43-7337264179461...-z^50+50*z^49-7608320154970245572376292980809948*z^14+10811254645381146528120022396491916044*z^3-11913615159357772540551773897287138656*z^4+6051956607854123248198916*z^27+1109882664*z^43-7337264179461...-z^50+50*z^49-7608320154970245572376292980809948*z^14+10811254645381146528120022396491916044*z^3-11913615159357772540551773897287138656*z^4+6051956607854123248198916*z^27+1109882664*z^43-7337264179461...

> coeff(%,z,50);

-1

>