SICP問題1.40

cubicの定義

(define (cubic a b c)
  (lambda (x) (+ (* x x x) (* a (* x x)) (* b x) c)))

三次式 (x^3) + a(x^2) + bx + cを定義

(define (test-cubic a b c x)
  (+ (* x x x) (* a (* x x)) (* b x) c))

newtons-methodと一緒に使用し、test-cubicの結果と比較

(newtons-method (cubic 0 -1 0) 5)
; 1.0000000000000342
(test-cubic 0 -1 0 1.0000000000000342)
; 6.838973831690964e-14
(newtons-method (cubic 5 2 6) 1)
; -4.84284873681615
(test-cubic 5 2 6 -4.84284873681615)
; -1.2434497875801753e-14

精度14桁くらい出てるのでOK