• let应用 找零点


    (define (search f neg-point pos-point)
      (let ((midpoint (average neg-point pos-point)))
        (if (close-enough? neg-point pos-point)
            midpoint
            (let ((test-value (f midpoint)))
              (cond ((positive? test-value)
                     (search f neg-point midpoint))
                    ((negative? test-value)
                     (search f midpoint pos-point))
                    (else midpoint))))))
    
    (define (close-enough? x y)
      (< (abs (- x y)) 0.001))
    
    (define (average x y)
      (/ (+ x y) 2))
    
    (define (half-interval-method f a b)
      (let ((a-value (f a))
            (b-value (f b)))
        (cond ((and (negative? a-value) (positive? b-value))
               (search f a b))
              ((and (negative? b-value) (positive? a-value))
              (search f b a))
              (else
                (error "Values are not of opposite sign" a b)))))
    
    (half-interval-method sin 2.0 4.0)
    (half-interval-method (lambda (x) (- (* x x x) (* 2 x) 3))
                          1.0
                          2.0)
    

      

  • 相关阅读:
    1. jQuery中的DOM操作
    jQuery查找节点(选择器)
    机器学习基础
    CRF
    NP
    LP
    kernel
    SVM
    凸优化和对偶
    语音识别 -- 概述
  • 原文地址:https://www.cnblogs.com/R4mble/p/7894249.html
Copyright © 2020-2023  润新知