Statistical computing homework 5

Statistical computing homework 5 (Spring 1998)

To see how much can be written about how little, read the Splus help on exp. It is amazing how much they say about so little. But actually, it is useful.

One way to layout the homework answer would be to make a table with each function in it with a short description. Say something like:

function Short description
sq() Takes a number and returns the square of the number.
d() Takes the derivative of a function.

Here is some samples that might cause your code to break.

Code that might cause problems Reason
d(d(sq))
Does d() return a function properly
test <- function(f) d(f)(1)
test(sq)
Does d() find the right lambda expression or just the name?
d(function(x) x*x)
does d() accept lambda expressions?
test.arg <- 5
normal(test.arg)(5)
does normal() handle arguments correctly
chisq <- function(){
   g <- transform(normal,sq);
   g(3)}
Can transform be called from inside a function? (In general this is a good thing to check since the handling of variables is kinda strange in Splus.)
test.arg <- 5
test <- function(mu) 
    { 
      normal(mu)(5)
    }
test(test.arg)
does normal() handle arguments correctly
large <- function(x) 1e20 * (x-.33)
root(large,0,1)
Does root incorrectly complain if it is given big numbers?
large <- function(x) 1e20 * (x-.33)
if(root(large,0,1) != .33) print("oops")
Does root find enough accuracy so that equality is preserved?
d(sq)(1e20)
Can d() handle large numbers?
d(sq)(1e-10)
Can d() handle small numbers?