Your der
returns a function of x
, which is fine. But your
(define (f x) (der (sin x) 0.5))
has a number of problems. First, since der
returns a function, all that f
does is return a function - it does no computation on x
. Probably you wanted:
(define f (der (sin x) 0.5))
so that f
is actually bound to a function of x
.
Second, the argument to der
is expected to be a function, but with (sin x)
you, at best, pass in a number.
In summary, probably you want something like:
(define f (der sin 0.5))
Note, your h
of 0.5 is probably too big to get a reasonable derivative (recall sin
is periodic outside of {0, 2pi}). You'll have no issues making h
very small. Of course, when you plot it you can step x
by 0.5 if you want.
Your der-multiple
function isn't correct in a number of ways. Here is the proper version:
(define (der-n f h n)
(if (zero? n)
f
(der-n (der f h) h (- n 1))))