Only problem is that you are might be breaking the theorem. Meaning some theorem do not work because your problem does not satisfy the conditions for the theorem. For example, the fundamental theorem of calculus sometimes fails, not because it is wrong but if you use a discountinous function it will not work (those were the assumed conditions). In this algorithm I know there is a special condition your function needs to satisfy (besides for being differenciable on some open interval) I forget what it is. So even if you did everything correct you might not satify a special condition.