也没什么

迷失了方向

练习 2.14 2.7 2.8 ~ 2.16 未完...
#lang racket


;: 区间加法
(define (add-interval x y)
  (make-interval (+ (lower-bound x) (lower-bound y))
                 (+ (upper-bound x) (upper-bound y))))

;: 区间乘法
(define (mul-interval x y)
  (let (
        (p1 (* (lower-bound x) (lower-bound y)))
        (p2 (* (lower-bound x) (upper-bound y)))
        (p3 (* (upper-bound x) (lower-bound y)))
        (p4 (* (upper-bound x) (upper-bound y))))
    (make-interval (min p1 p2 p3 p4)
                   (max p1 p2 p3 p4))))
;: 区间除法
(define (div-interval x y)
  (mul-interval x
                (make-interval (/ 1.0 (upper-bound y))
                               (/ 1.0 (lower-bound y)))))

;: 练习  2.7
(define (make-interval a b) (cons a b))

;: 答安
(define (upper-bound x)
  (let ((a (car x))
        (b (cdr x)))
    (if (> a b)
        a
        b)))

(define (lower-bound x)
  (let ((a (car x))
        (b (cdr x)))
    (if (> a b)
        b
        a)))
;: 测试
(define x (make-interval 3 5))
(upper-bound x)
(lower-bound x)

;:练习2.8 两个区间的差
;: 差的最小值 =-?
;: 差的最大值 =-?
(define (sub-interval x y)
  (make-interval (- (lower-bound x) (lower-bound y))
                 (- (upper-bound x) (upper-bound y))))

;: 练习 2.9 区间的宽带 =上界下界之差的一半
;: 宽度
(define (width-interval x)
  (/ 2 ( + (upper-bound x)
           (lower-bound x))))

;: 对于+法
;(define (add-interval x y)
;  (make-interval (+ (lower-bound x) (lower-bound y))
;                 (+ (upper-bound x) (upper-bound y))))

(define a (make-interval '1 '2))
(define b (make-interval '3 '4))

;(add-interval a b) =>
;  (make-interval (+ (lower-bound a) (lower-bound b))
;                 (+ (upper-bound a) (upper-bound b))))
;=>(make-interval (+ '1 '3) (+ '2 '4))
;=> 宽度= (/ 2
;          (- (+ '2 4)
;             (+ '1 '3)))
;: '2 - '1 + '4 - '3 / 2                   => 
;: (('2 - '1) + ('4 - '3)) / 2             =>
;: (/ 2 (+ (- '2 '1)
;:         (- '4 '3)))                     =>  
阅读更多
版权声明:知行合一 https://blog.csdn.net/yemeishenme/article/details/51555632
文章标签: sicp
想对作者说点什么? 我来说一句

20180308:git2.16 + git gui汉化

2018年03月08日 37.33MB 下载

C F爆发者2.7 2.8

2008年12月19日 795KB 下载

没有更多推荐了,返回首页

不良信息举报

练习 2.14 2.7 2.8 ~ 2.16 未完...

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭