【SICP练习】134 练习3.65

练习3-65

原文

Exercise 3.65. Use the series

ln2 = 1- 1/2 + 1/3 - 1/4 + ……

to compute three sequences of approximations to the natural logarithm of 2, in the same way we did above for . How rapidly do these sequences converge?

代码

(define (ln2-summands n)
        (cons-stream (/ 1.0 n)
                     (stream-map - (ln2-summands (+ n 1)))))
(define ln2-stream
        (partial-sums (ln2-summands 1)))
时间: 2024-08-07 10:26:55

【SICP练习】134 练习3.65的相关文章

SICP 1-33 1-34 1-35

ex1-32 要求利用过程返回值给出一个用于计算 f(f (x))这样的函数过程 ex1-33要求计算一个函数的平滑函数g(x)=(f(x-dx)+f(x)+f(x+dx))/3 并利用ex1-32给出的过程进行多次的平滑运算以下,给出代码 (define (smooth f) (lambda (x) (/ (+ (f (- x .001)) (f x) (f (+ x .001))) 3))) (define (repeated f x) (lambda (times) (if (= time

15 THINGS ALL GIRLS SHOULD KNOW ABOUT THEIR VAGINA

Here are 15 facts that EVERY GIRL should know about her vagina. Don’t be shy! Your vagina is part of your body, and it will be for the rest of your life! So it’s good to know at least some basic information about it! 1. What is the Vagina? It is the

结合JSFL/actionscript 实现轮廓动画

动画前半段通过JSFL获取轮廓数据,并在EnterFrame中逐个边缘画出的:后半段机枪动画是美术做好的flash动画. 这里只放出actionscript代码,而JSFL代码涉及到一个工程,暂时保密. package { import flash.display.MovieClip; import flash.display.Sprite; import flash.events.Event; import flash.utils.setTimeout; /** * * @author ken

记次浙大月赛 134 - ZOJ Monthly, June 2014

链接 虽做出的很少,也记录下来,留着以后来补..浙大题目质量还是很高的 B 并查集的一些操作,同类和不同类我是根据到根节点距离的奇偶判断的,删点是直接新加一个点,记得福大月赛也做过类似的,并差集的这类关系题目还是比较常见的,有空深究一下. 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6

134在单元格中自动排列指定的数据

效果如下: ViewController.h 1 #import <UIKit/UIKit.h> 2 3 @interface ViewController : UITableViewController 4 @property (strong, nonatomic) NSMutableArray *mArrDataList; 5 @property (strong, nonatomic) NSMutableArray *mArrSortedCollation; 6 7 @end ViewCo

No.65 Valid Number

No.65 Valid Number Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => true Note: It is intended for the problem statement to

SICP 习题 (1.46)解题总结

SICP 习题 1.46 要求我们写一个过程iterative-improve,它以两个过程为参数,其中一个参数用来检测猜测是否足够好,另一个参数用来改进猜测.过程iterative-improve应该返回另一个过程,所返回的过程接收一个参数作为初始猜测,然后不断改进猜测直到结果足够好.题目还要求我们使用iterative-improve重写1.1.7的sqrt过程和1.3.3节的fixed-point过程. 因为涉及到高阶函数,所以整个题目理解起来有一点点费劲.不过这道题作为第一章的收官题确实

SICP 1.19

解:这道题很有意思,结论是斐波那契数也可以用对数时间复杂度获得. 通过Tpq(Tpq)=TPQ建立方程,解得: P=pp+qq Q=qq+2pq 程序如下: (define (fib n)   (define (even? n)     (= (remainder n 2) 0))   (define (fib-iter a b p q count)     (cond ((= count 0) b)           ((even? count) (fib-iter a           

SICP 1.12

解: (define (pascal n)   (define (get n i)     (cond ((<= i 1) 1)           ((>= i n) 1)           (else (+ (get (- n 1) (- i 1))                    (get (- n 1) i)))))   (define (iter i n)     (if (<= i n)         (and (print (get n i))