練習2 11 練習2 20

2021-06-20 05:48:41 字數 3353 閱讀 1868

1.練習2.11

(define (mul-interval x y)

(let ((x1 (lower-bound x))

(x2 (upper-bound x))

(y1 (lower-bound y))

(y2 (upper-bound y)))

(let

((zzx (and (>= x1 0) (>= x2 0)))

(zzy (and (>= y1 0) (>= y2 0)))

(fzx (and (< x1 0) (>= x2 0)))

(fzy (and (< y1 0) (>= y2 0)))

(ffx (and (< x1 0) (< x2 0)))

(ffy (and (< y1 0) (< y2 0))))

(cond (zzy (cond (zzx (make-interval (* x1 y1) (* x2 y2)))

(fzx (make-interval (* x1 y2) (* x2 y2)))

(ffx (make-interval (* x1 y2) (* x2 y1)))))

(fzy (cond (zzx (make-interval (* x2 y1) (* x2 y2)))

(fzx (make-interval (min (* x1 y2) (* x2 y1))

(max (* x1 y1) (* x2 y2))))

(ffx (make-interval (* x1 y2) (* x1 y1)))))

(ffy (cond (zzx (make-interval (* x2 y1) (* x1 y2)))

(fzx (make-interval (* x2 y1) (* x1 y1)))

(ffx (make-interval (* x2 y2) (* x1 y1)))))))))

2.練習2.12

(define (mul-interval x y)

(let ((x1 (lower-bound x))

(x2 (upper-bound x))

(y1 (lower-bound y))

(y2 (upper-bound y)))

(let

((zzx (and (>= x1 0) (>= x2 0)))

(zzy (and (>= y1 0) (>= y2 0)))

(fzx (and (< x1 0) (>= x2 0)))

(fzy (and (< y1 0) (>= y2 0)))

(ffx (and (< x1 0) (< x2 0)))

(ffy (and (< y1 0) (< y2 0))))

(cond (zzy (cond (zzx (make-interval (* x1 y1) (* x2 y2)))

(fzx (make-interval (* x1 y2) (* x2 y2)))

(ffx (make-interval (* x1 y2) (* x2 y1)))))

(fzy (cond (zzx (make-interval (* x2 y1) (* x2 y2)))

(fzx (make-interval (min (* x1 y2) (* x2 y1))

(max (* x1 y1) (* x2 y2))))

(ffx (make-interval (* x1 y2) (* x1 y1)))))

(ffy (cond (zzx (make-interval (* x2 y1) (* x1 y2)))

(fzx (make-interval (* x2 y1) (* x1 y1)))

(ffx (make-interval (* x2 y2) (* x1 y1)))))))))

3.練習2.13

中文的翻譯太差了,句中的「兩個被乘區間的誤差」應該是「被乘區間的百分比誤差」吧,很生氣。。。

4.練習2.14

5.練習2.15

因為引入的誤差少,所以更精確

6.練習2.16

設計一種好難啊

7.練習2.17

(define (last-pair items)

(let ((len (length items)))

(define (last-pair-iter item tmplen)

(if (= tmplen 1)

item

(last-pair-iter (cdr item) (- tmplen 1))))

(last-pair-iter items len)))

8.練習2.18

(define (reverse items)

(define (reverse-iter tmpitems result)

(if (null? tmpitems)

result

(reverse-iter (cdr tmpitems)

(cons (car tmpitems) result))))

(reverse-iter items '()))

9.練習2.19

(define (first-denomination list1)

(car list1))

(define (except-first-denomination list1)

(cdr list1))

(define (no-more? list1)

(null? list1))

10.練習2.20

(define (same-parity . other)

(define (even-number? number)

(= (remainder number 2) 0))

(define (same-parity-recur even items)

(if (null? items)

'()(let ((now-even (even-number? (car items)))

(next (same-parity-recur even (cdr items))))

(if (or (and even now-even)

(and (not even) (not now-even)))

(cons (car items) next)

next))))

(let ((evenodds (even-number? (car other))))

(same-parity-recur evenodds other)))

2 11練習 練習5(1) p37

練習 5 1 修改前乙個練習,將dataonly中的資料在main 方法中賦值並列印出來。public class dataonlytest dataonly data new dataonly data.i 47 data.d 1.1 data.b false system.out.println...

浙大版《C語言程式設計(第3版)》練習2 11

本題目要求計算下列分段函式f x 的值 注 可在標頭檔案中包含math.h,並呼叫sqrt函式求平方根,呼叫pow函式求冪。輸入格式 輸入在一行中給出實數x。輸出格式 在一行中按 f x result 的格式輸出,其中x與result都保留兩位小數。輸入樣例1 10輸出樣例1 f 10.00 3.1...

SICP練習 1 練習1 1 練習1 5

練習1.1 這道題主要是關於簡單的數字運算,我們看完之後可以在 mit scheme 中進行驗算。如果環境不熟悉,可以參見 scheme 歸納 的第一篇博文。如果發現在 mit scheme 等環境上的運算結果和自己算的不一樣,也應該再仔細看看在書寫 的時候有沒有手誤。練習1.2 這是一道將表示式轉...