Without looking at it in any depth I would suspect the pow function. Consider th function sqrt(x). if x==0 sqrt(x) is well defined, but the derivative is 1/(2*sqrt(x)) which is not well defined. Exactly how this comes out of a pow I don't see, but probably something like this is going on.