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); |
| > | diff(f,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[0](z); p[1](z); p[2](z); |
| > | p[50](z); |
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
| > | coeff(%,z,50); |
| > |