scip習題1.7解答
綜合了習題1.6提出的誤差過大問題,採用相對誤差進行求值,題目是要求使用牛頓近似求立方根公式寫出scheme過程:
(define (square x) (* x x))
(define (divided_by_3 x y)(/ (+ x y) 3))
(define (improve guess x)
(divided_by_3 (/ x (square guess)) (* 2 guess)))
(define constant 0.0001)
(define (good_enough? old_guess guess)
(< (abs (/ (- guess old_guess) guess)) constant))
(define (curt old_guess guess x)
(if (good_enough? old_guess guess)
guess
(curt guess (improve guess x) x)))
(define (simple_curt x)(curt 0.1 1 x))
測試一下:(define (divided_by_3 x y)(/ (+ x y) 3))
(define (improve guess x)
(divided_by_3 (/ x (square guess)) (* 2 guess)))
(define constant 0.0001)
(define (good_enough? old_guess guess)
(< (abs (/ (- guess old_guess) guess)) constant))
(define (curt old_guess guess x)
(if (good_enough? old_guess guess)
guess
(curt guess (improve guess x) x)))
(define (simple_curt x)(curt 0.1 1 x))
> (simple_curt 27)
3.0000000000000975834575646
> (simple_curt 8)
2.0000000000120622386311755
> (simple_curt 9)
2.0800838232385225245408740
3.0000000000000975834575646
> (simple_curt 8)
2.0000000000120622386311755
> (simple_curt 9)
2.0800838232385225245408740
相關文章
- Java習題解答12Java
- 習題解答chapter04APT
- [詹興致矩陣論習題參考解答]習題1.6矩陣
- [詹興致矩陣論習題參考解答]習題4.14矩陣
- 解答關於學習前端的一些問題前端
- JVM問題及解答JVM
- iOS 面試題解答二iOS面試題
- 周志華《機器學習》課後習題解答系列(一):目錄機器學習
- Docker面試問題與解答Docker面試
- Oracle常用問題及解答Oracle
- ABAP面試題及其解答(轉)面試題
- xmlhttp的問題,盼望解答XMLHTTP
- Oracle面試題目及解答Oracle面試題
- APatch常見問題解答
- 曹廣福實變函式論與泛函分析部分習題解答 習題二 三 四函式泛函分析
- 《C和指標》第三章課後習題解答指標
- ConcurrentHashMap (jdk1.7)原始碼學習HashMapJDK原始碼
- 1.7
- 練習負載均衡時遇到的一些問題,求解答負載
- [提問交流]OneThink學習日記(更有很多問題求解答!)
- 軟體新人問題解答(一)
- Ubuntu 常見問題和解答Ubuntu
- Python list,dict問題解答Python
- 測試面試題目求解答面試題
- Linux常見問題解答Linux
- [資料庫]50道經典SQL練習題,使用MySQL5.7解答資料庫MySql
- 周志華《機器學習》課後習題解答系列(四):Ch3.4 - 交叉驗證法練習機器學習
- [譯] HTTP/2 常見問題解答HTTP
- RapidWeaver 8常見問題解答API
- 小遊戲引擎常見問題解答遊戲引擎
- [翻譯]K-99問題解答
- (轉載)Autodesk面試技術題解答面試
- 【from MM】Flex 常見問題解答Flex
- 一道sql面試題的解答SQL面試題
- 用Python解答ProjectEuler問題(4)PythonProject
- 用Python解答ProjectEuler問題(3)PythonProject
- 用Python解答ProjectEuler問題(1)PythonProject
- 幫忙解答一道面試題面試題