next up previous
Next: About this document ...

Problems of the day
1.
The Fibonacci numbers $F_0, F_1, \ldots$ are defined by: F0 = F1 = 1, and Fn = Fn-1 + Fn-2 for $n \geq 2$. Write a recursive Maple routine that calculates the n'th Fibonacci number.
2.
What does the following Maple procedure do?
> tolerance := 0.01;

                           tolerance := .01

> WhatAmI := proc (f, x, y)
   local x2, y2;
   global tolerance;
 
   x2 := evalf(x); y2 := evalf(y);
   if abs (x2-y2) < tolerance and abs(f(x2)-f(y2)) < tolerance then
     RETURN ((f(x2)+f(y2))*(y2-x2)/2);
   else
     RETURN (WhatAmI (f, x2, (x2+y2)/2) + WhatAmI(f, (x2+y2)/2, y2));
   fi;
  end:
> WhatAmI(cos, 0, 1);

                             .8414667052

>
3.
Write a recursive Maple procedure that given a piece of text (eg: ``Hello'') returns the text reversed (eg: ``olleH'').
4.
Write a recursive Maple procedure that given a function fand an interval [a,b] finds a zero of f in [a,b] (you may assume that f(a) and f(b) have opposite signs) by dividing the interval into halves, then quarters etc, until a zero is found to some tolerance. (An interval [c,d] will contain a zero if f(c) and f(d) have opposite signs -- exploit this).



 

Duncan Sands
1998-11-12