2.9

练习 2.9 区间的宽度就是其上界和下界之差的一半,区间宽度是有关区间所描述的相应数值的非确定性的一种度量。对于某些算术运算,两个区间的组合结果的宽度就是参数区间的宽度的函数,而对其他运算,组合区间的宽度则不是参数区间的函数。证明两个区间的和(与差)的宽度就是被加(或减)的区间的宽度的函数。举例说明,对于乘和除而言,情况并非如此。


其实,从这些算术运算的定义即可看出这一点。对于加与减,结果区间的宽度其实是可以由参数区间的宽度计算出来的。即每一种参数区间的宽度组合,对应着唯一的结果区间的宽度。

由于减法本质上加法的一个变换,所以只需要看加法的区间宽度映射关系就可以了。

width = (upper-bound - lower-bound) / 2
width-of-sum = (upper-bound-of-sum - lower-bound-of-sum) / 2
            =  ((upper-bound-of-x + upper-bound-of-y) 
                    - (lower-bound-of-x + lower-bound-of-y)) / 2
            =   width-of-x + width-of-y

对于减法,结果区间的宽度也是参数区间的宽度之和。同样的宽度输入,只能得到一个结果。

width = (upper-bound - lower-bound) / 2
width-of-sum = (upper-bound-of-sum - lower-bound-of-sum) / 2
            =  ((upper-bound-of-x - lower-bound-of-y) 
                    - (lower-bound-of-x - upper-bound-of-y)) / 2
            =   width-of-x + width-of-y
(define (make-interval a b) (cons a b))
(define upper-bound cdr)
(define lower-bound car)
(define (add-interval x y) 
    (make-interval (+ (lower-bound x) (lower-bound y))
                    (+ (upper-bound x) (upper-bound y))))
(define (sub-interval x y) (add-interval x (make-interval (- 0 (upper-bound y)) (- 0 (lower-bound y)))))
(define (subtract-interval x y)
    (define p1 (- (lower-bound x) (lower-bound y)))
    (define p2 (- (lower-bound x) (upper-bound y)))
    (define p3 (- (upper-bound x) (lower-bound y)))
    (define p4 (- (upper-bound x) (upper-bound y)))

    (make-interval (min p1 p2 p3 p4) (max p1 p2 p3 p4)))

对于乘法,可以举一个例子, [1, 2] * [1, 2]。

(define (mul-interval x y)
    (define p1 (* (lower-bound x) (lower-bound y)))
    (define p2 (* (lower-bound x) (upper-bound y)))
    (define p3 (* (upper-bound x) (lower-bound y)))
    (define p4 (* (upper-bound x) (upper-bound y)))

    (make-interval (min p1 p2 p3 p4) (max p1 p2 p3 p4))
)

(define (width x) (/ (- (upper-bound x) (lower-bound x)) 2))
(define int1 (make-interval 1 2))
(define int2 (make-interval 1 2))

int1
int2
(define int3 (mul-interval int1 int2))
int3

可见,输入的参数区间的宽度是 0.5 和 0.5,得到的结果区间的宽度是 1.5。只要再构造另外两个参数区间,宽度都是 0.5 和 0.5, 但是结果区间的宽度不是 1.5,就证明了,两个区间相乘后得到的区间宽度,不是输入参数区间的宽度的函数。

(define int4 (make-interval 2 3))
(define int5 (make-interval 2 3))

(define int6 (mul-interval int4 int5))
int6

得到的结果区间的宽度是 (9-4)/2 = 2.5,不是 1.5。

results matching ""

    No results matching ""