SICP: 第一章 之 牛顿法

#lang racket

(define (newton-transform g)
  (define dx 0.00001)
  (define (deriv g)
    (lambda (x)
      (/ (- (g (+ x dx)) (g x)) dx)
    );lambda
    );deriv

  (lambda (x)
    (- x (/ (g x) ((deriv g)x))));lambda
  );newton-transform

(define (fixed-point f guess)
  (define tolerance 0.00001);公差
  (define (get-point x)
    (let ((result (f x)))
      (if (< abs(- result x) tolerance)
      result
      (get-point (/ (+ result x) 2))
     );if
      );let
    );get-point
  (get-point guess)
  );fixed-point

(define (newtons-method g guess)
  (fixed-point (newton-transform g) guess)
  );newtons-method

posted on 2015-04-04 11:07  Zachary_wiz  阅读(179)  评论(0编辑  收藏  举报

导航