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

#lang racket

;: 区间加法
(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))))

;: 对于+法
;  (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))

;  (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)))                     =>


• 本文已收录于以下专栏：

举报原因： 您举报文章：练习 2.14 2.7 2.8 ~ 2.16 未完... 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)