Created
July 7, 2021 05:56
-
-
Save yanfeng42/f5d2db273f687b42712405e9d674025d to your computer and use it in GitHub Desktop.
sicp 1.40 计算任意 方程的近似解
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (newton-transform g) | |
(lambda (x) | |
(- x (/ (g x) ((deriv g) x))))) | |
(define (deriv g) | |
(lambda (x) | |
(/ (- (g (+ x dx)) (g x)) | |
dx) | |
) | |
) | |
(define dx 0.00001) | |
(define (cube x) (* x x x)) | |
(define (square x) (* x x)) | |
(define (newtons-method g guess) | |
(fixed-point (newton-transform g) guess) | |
) | |
(define (cubic a b c) | |
(lambda (x) (+ (cube x) (* a (square x)) (* b x) c)) | |
) | |
(define (my-cubic a b c) | |
(newtons-method (cubic a b c) 1) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这是一个非常有价值的工具方法. 比如: 估算自己的 计算结果, 是否正确.(快速演算 -- 家长 育儿必备哈)
类似的问题, 我以前有思考过. 当时自己的思路是: 从某一个不可能的值, 逐个 遍历. 比如: -99, -88.999, -88.998.....
很明显, 我的 暴力穷举猜测 法, 明显效率更低, 兼容性也更低.