Your h
of .00000000000001
is too small; so small that you are running into rounding errors. Here is a result with another h
(define der-of-cube-n (der-n cube 0.0001 2))
> (der-of-cube-n 5)
30.000597917023697
Note: second derivative of x^3
is 6x
.
Of course, one of the important attributes of Scheme is that it supports exact numbers of arbitrary precision. So if you really want h
to be that small you can formulate your inputs to be 'exact'. Like this:
> (define der-of-cube-n (der-n cube (/ 10000000000000) 2))
> (der-of-cube-n 5)
150000000000003/5000000000000
> (rationalize (der-of-cube-n 5) 0.01)
3e1