Updated program to take a multi-dimensional function. Problems as the tolerance is set lower, but seems to be largely working from initial test