乐正

Actions speak louder than words.

Sicp-ex1-40

问题

请定义一个过程cubic,它和newtons-method过程一起使用在下面的表达式里:

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

能逼近三次方程$x^3 + ax^2 + bx + c$的零点。

解答

练习1.40 (ex1-40.scm) download
1
2
3
4
5
6
7
8
(define (cube x) (* x x x))

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

测试

1
2
3
4
5
6
;;; Load p46-fixed-point.scm
;;; Load p49-deriv.scm
;;; Load p49-newton-transform.scm

(newtons-method (cubic 3 4 5) 1.0)
;Value: -2.2134116627621956

draft

« sicp-ex1-39 sicp-ex1-41 »

Comments