LISP 开方根

(define (sqrt x y z)
(define (half m n) (/ (+ m n) 2))
(define (square m) (* m m))
(cond ((and ( < (- (square (half x y)) z) 0.0001) ( > (- (square (half x y)) z) (- 0.0001))) (half x y))
((> (- (square (half x y)) z) 0.0001) (sqrt x (half x y) z))
((< (- (square (half x y)) z) (- 0.0001)) (sqrt (half x y) y z))))

x 区间开始

y 区间结束

z求的开平方数

调用

(sqrt 0 2 2)

1 ]=> (sqrt 0 2 2)
;Value: 11585/8192

猜你喜欢

转载自www.cnblogs.com/cshunter/p/9274741.html
今日推荐