1.29
(define (inc n) (+ n 1))
(define (cube a) (* a a a))
(define (sum term a next b)
(if (> a b)
0
(+ (term a)
(sum term (next a) next b))))
(define (sum-cubes a b)
(sum cube a inc b))
(define (integral f a b dx)
(define (add-dx x) (+ x dx))
(* (sum f (+ a (/ dx 2.0)) add-dx b)
dx))
(define (simpson f a b n)
(define h (/ (- b a) n))
(define (y k) (f (+ a (* k h))))
(define (next x) (+ x 1))
(define (term i)
(+ (y (- (* 2 i) 2))
(y (* 2 i))
(* 4 (y (- (* 2 i) 1)))))
(/ (* h (sum term 1 next (/ n 2))) 3))
(define (simpson1 f a b n)
(define (get-h) (/ (- b a) n))
(define (get-y k) (f (+ a (* k (get-h)))))
(define (simpson-term k)
(cond ((= k 0) (get-y k))
((= k n) (get-y k))
((= (remainder k 2) 0) (* 2.0 (get-y k)))
(else (* 4.0 (get-y k)))))
(define (simpson-next k) (+ k 1))
(* (/ (get-h) 3.0) (sum simpson-term 0 simpson-next n)))
(sum-cubes 1 10)
(integral cube 0 1 0.01)
(simpson cube 0.0 1.0 100)
(simpson1 cube 0.0 1.0 100)
(integral cube 0 1 0.001)
(simpson cube 0.0 1.0 1000)
(simpson1 cube 0.0 1.0 1000)
1.30
(define (inc n) (+ n 1))
(define (addself n) (+ (* 2 n) 1))
(define (cube a) (* a a a))
(define (f a b result)
(cond ((< a b) (f (+ a 1) b (+ a result)))
((= a b) (+ a result))))
(define (sum term a next b)
(define (iter a result)
(if (> a b)
result
(iter (next a) (+ result (term a)))))
(iter a 0))
(f 1 3 0)
(sum cube 1 inc 10)
1.31
(define (inc n) (+ n 1))
(define (cube a) (* a a a))
(define (product term a next b)
(if (> a b)
1
(* (term a)
(product term (next a) next b))))
(define (product-iter term a next b)
(define (iter a result)
(if (> a b)
result
(iter (next a) (* result (term a)))))
(iter a 1))
(define (product-cubes a b)
(product cube a inc b))
(define (product-cubes-iter a b)
(product-iter cube a inc b))
(product-cubes 1 3)
(product-cubes-iter 1 3)
(define (double-even n)
(* 4 n n))
(define (double-odd n)
(+ (- (* 4 n n) (* 4 n)) 1))
(define (mypi n)
(* (/ (product double-even 1.0 inc n) (* (product double-odd 1.0 inc n) (* 2 n))) 2))
(mypi 80.0)
1.32
(define (inc n) (+ n 1))
(define (cube a) (* a a a))
(define (accumulate combiner null-value term a next b)
(if (> a b)
null-value
(combiner (term a)
(accumulate combiner null-value term (next a) next b))))
(define (accumulate-iter combiner null-value term a next b)
(define (iter a result)
(if (> a b)
result
(iter (next a) (combiner result (term a)))))
(iter a null-value))
(define (sum term a next b)
(accumulate + 0 term a next b))
(define (sum-iter term a next b)
(accumulate-iter + 0 term a next b))
(define (sum-cubes a b)
(sum cube a inc b))
(define (sum-cubes-iter a b)
(sum-iter cube a inc b))
(sum-cubes 1 10)
(sum-cubes-iter 1 10)
1.33
(define (square n)
(* n n))
(define (smallest-divisor n)
(find-divisor n 2))
(define (find-divisor n test-divisor)
(cond ((> (square test-divisor) n) n)
(( divides? test-divisor n) test-divisor)
(else (find-divisor n (+ test-divisor 1)))))
(define (divides? a b)
(= (remainder b a) 0))
(define (prime? n)
(= n (smallest-divisor n)))
(define (plain n) n)
(define (inc n) (+ n 1))
(define (filtered-accumulate filtered combiner null-value term a next b)
(if (> a b)
null-value
(if (filtered a)
(combiner (term a) (filtered-accumulate filtered combiner null-value term (next a) next b))
(filtered-accumulate filtered combiner null-value term (+ a 1) next b))))
(define (sum term a next b)
(filtered-accumulate prime? + 0 term a next b))
(define (sum-plain a b)
(sum plain a inc b))
(sum-plain 1 10)
(define (product-prime n)
(product plain 1 inc n))
(define (product term a next b)
(define (co-prime? i)
(if (and (= (gcd i b) 1) (< i b))
#t
#f))
(filtered-accumulate co-prime? * 1 term a next b))
(product-prime 10)
分享到:
相关推荐
SICP 习题答案 计算机程序的构造和解释 1-3章 习题答案
SICP习题解答,主要第一章的内容习题答案
NULL 博文链接:https://pengpeng.iteye.com/blog/1344689
sicp in python 中文版 sicp in python 中文版 sicp in python 中文版 !!!download>>>https://github.com/wizardforcel/sicp-py-zh
SICP中文第二版SICP中文第二版SICP中文第二版SICP中文第二版SICP中文第二版
scheme编译器最新版,Windows下直接安装即可运行,sicp刷题必备。祝大家早日学到sicp之精髓~
SICP-Python版本
SICP 使用的scheme解释器 以前叫DrScheme
sicp 2.2.4节图形语言的racket程序包,配置路径,C:\Users\Administrator\AppData\Roaming\Racket
Python SICP epub版本,很适合学习抽象的思想,用Python版本比lisp更实用
SICP 解题集
SICP CHINESE ENGLISH THE SECOND EDITION SICP CHINESE ENGLISH THE SECOND EDITION
sicp in python 中文版 sicp in python 中文版 sicp in python 中文版 download : https://github.com/wizardforcel/sicp-py-zh
sicp 2ed高清pdf,以及相对应的mit课程资料及习题答案打包,中文版的视频在这里http://i.youku.com/i/UNTcxODk3ODQw/videos?spm=a2hzp.8244740.0.0
资源来自pypi官网。 资源全名:sicp-0.0.1b102.dev4.tar.gz
sicp-in-python(中文版+英文版)PDF 背景. SICP 全称Structure and Interpretation of Computer Programs,翻译过来叫《计算机程序的构造和解释》使用python
资源名称:sicp 和 操作系统:精髓与设计原理第七版资源截图: 资源太大,传百度网盘了,链接在附件中,有需要的同学自取。
SICP_章_1-3 我对SICP第二版第1-3章的解决方案: 书中练习来自示例分配/ psets 项目位于 最后,来自考试
经典书籍《计算机程序的构造与解释》,UCB热门课程CS61a的官方教材