Yes, it's actually very ugly to some times return a string and some times return a double, I did this just to directly print the variable... Now I am simply returning the derivative, and infinite if it cannot be computed because of having to few samples (iterations).