计算机程序的构造和解释 练习 1.36
2016-05-22 22:20
369 查看
#lang racket (define tolerance 0.00001) (define (fixed-point f first-guess) (define (close-enough? v1 v2) (< (abs (- v1 v2)) tolerance)) (define (try guess) (display guess) (newline) (let ((next (f guess))) (if (close-enough? guess next) next (try next)))) (try first-guess)) ;:求黄金分割 ;:(fixed-point (lambda (x) (+ 1 (/ 1 x))) 1.0) ;: 求 x^x=1000的根 (fixed-point (lambda (x) (/ (log 1000) (log x))) 3) (newline) (newline) ;: 求 x^x=1000的根 (fixed-point (lambda (x) (/ (+ x (/ (log 1000) (log x))) 2)) 3)
结果:
欢迎使用 DrRacket, 版本 6.5 [3m].
语言: racket, with debugging; memory limit: 128 MB.
3
6.287709822868153
3.757079790200296
5.218748919675315
4.180797746063314
4.828902657081293
4.386936895811029
4.671722808746095
4.481109436117821
4.605567315585735
4.522955348093164
4.577201597629606
4.541325786357399
4.564940905198754
4.549347961475409
4.5596228442307565
4.552843114094703
4.55731263660315
4.554364381825887
4.556308401465587
4.555026226620339
4.55587174038325
4.555314115211184
4.555681847896976
4.555439330395129
4.555599264136406
4.555493789937456
4.555563347820309
4.555517475527901
4.555547727376273
4.555527776815261
4.555540933824255
4.555532257016376
3
4.643854911434076
4.571212264484558
4.558225323866829
4.555994244552759
4.555613793442989
4.5555490009596555
4.5555379689379265
4.55553609061889
相关文章推荐
- 用环境模型来理解javascript中的闭包
- 对嵌套映射的理解
- SICP Exercise 1.13
- sicp习题答案和范例代码 - 第一章
- sicp习题答案和范例代码 - 第二章 2.1
- SICP第一章——构造过程抽象之程序设计的基本元素(1.1)笔记及习题解答
- SICP-《计算机程序的构造和解释》之习题分析与收获——练习1.30
- SICP-《计算机程序的构造和解释》之习题分析与收获——练习1.29
- 游走于数据与代码之间
- 换零钱问题迭代解法
- Structure and Interpretation of Computer Programs 读书笔记
- 应用序和正则序
- [SICP Notes] 1.1 The Elements of Programming
- 《计算机程序的构造与解释》习题自编代码(第1章)(未完待更)
- 【Structure and interpretation of Computer Programs 】学习记录兼导言
- 第一章笔记整理
- SICP-练习2.34
- SICP-练习2.17
- 计算斐波纳契数,分析算法复杂度
- SICP-求幂