练习 1.40

首先根据公式 \(x^3 + ax^2 + bx + c\) 写出相应的 cubic 过程, 它的返回值是一个接受参数 x 的过程:

;;; 40-cubic.scm

(load "8-cube.scm")

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

然后将 cubic 过程传给 newtons-method 就可以进行测试了:

1 ]=> (load "p50-newtons-method.scm")

;Loading "p50-newtons-method.scm"...
;  Loading "p46-fixed-point.scm"... done
;  Loading "p49-newton-transform.scm"...
;    Loading "p49-deriv.scm"... done
;  ... done
;... done
;Value: newtons-method

1 ]=> (load "40-cubic.scm")

;Loading "40-cubic.scm"...
;  Loading "8-cube.scm"... done
;... done
;Value: cubic

1 ]=> (newtons-method (cubic 3 2 1) 1.0)

;Value: -2.3247179572447267

1 ]=> (newtons-method (cubic 2 5 5) 1.0)

;Value: -1.2332293376819243

讨论

blog comments powered by Disqus