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

来源:互联网 发布:金海岸大酒店网络地图 编辑:程序博客网 时间:2024/05/01 14:22
#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)))                     =>  
0 0