SICP 全笔记

Exercise 1.40. Define a procedure cubic that can be used together with the newtons-method procedure in expressions of the form

(newtons-method (cubic a b c) 1)

to approximate zeros of the cubic x3 + ax2 + bx + c.

定义 cubic 过程为:

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

下面是几个测试:

(define (get-cubic-zeros a b c)
  (newtons-method (cubic a b c) 1))

; (get-cubic-zeros -3 3 -1) or (x-1)^3=0
; => 1

; (get-cubic-zeros 0 -3 2) or (x+2)(x-1)^2=0
; => 1

; (get-cubic-zeros -0.5 -4 -2.5) or (x-2.5)(x+1)^2=0
; => -1.0000050459462515

; (get-cubic-zeros 11/12 1/4 1/48) or (x+1/2)(x+1/4)(x+1/6)
; => -.16666666563804614