-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
196 additions
and
81 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
(define tolerance 0.00001) | ||
|
||
(load "fixed-point.scm") | ||
(load "fixed-point.lib.scm") | ||
|
||
(display (fixed-point (lambda (x) (+ 1 (/ 1 x))) 1.0)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
(define tolerance 0.00001) | ||
|
||
(define (fixed-point f first-guess) | ||
(define tolerance 0.00001) | ||
(define (close-enough? x y) | ||
(< (abs (- x y)) tolerance)) | ||
(define (try guess) | ||
(define (try steps guess) | ||
(display "-> ") | ||
(display guess) | ||
(display "#") | ||
(display steps) | ||
(newline) | ||
(let ((next (f guess))) | ||
(if (close-enough? guess next) | ||
guess | ||
(try next)))) | ||
(try first-guess)) | ||
(try (+ steps 1) next)))) | ||
(try 1 first-guess)) | ||
|
||
(define (average x y) | ||
(/ (+ x y) 2)) | ||
|
||
; Noraml approach | ||
(fixed-point (lambda (x) (/ (log 1000) (log x))) 2.0) | ||
; noraml approach | ||
(display "=== normal approach ===") | ||
(newline) | ||
(fixed-point (lambda (x) (/ (log 1000) (log x))) 2.0) | ||
|
||
; Using average damping | ||
; use average damping | ||
(display "=== average damping ===") | ||
(newline) | ||
(fixed-point (lambda (x) (average x (/ (log 1000) (log x)))) 2.0) |
This file contains 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
This file contains 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
This file contains 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
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(define (fixed-point f first-guess) | ||
(define tolerance 0.00001) | ||
(define (close-enough? x y) | ||
(< (abs (- x y)) tolerance)) | ||
(define (try guess) | ||
(let ((next (f guess))) | ||
(if (close-enough? guess next) | ||
guess | ||
(try next)))) | ||
(try first-guess)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
(define tolerance 0.00001) | ||
(load "fixed-point.lib.scm") | ||
|
||
(define (fixed-point f first-guess) | ||
(define (close-enough? x y) | ||
(< (abs (- x y)) tolerance)) | ||
(define (try guess) | ||
(let ((next (f guess))) | ||
(if (close-enough? guess next) | ||
guess | ||
(try next)))) | ||
(try first-guess)) | ||
; y = cos(y) | ||
; 0.739089 | ||
(display (fixed-point cos 1.0)) | ||
(newline) | ||
|
||
; y = sin(y) + cos(y) | ||
; 1.258722 | ||
(display (fixed-point (lambda (y) (+ (sin y) (cos y))) 1.0)) | ||
|
||
; calculate square root, y = x/y -> y = 1/2(y + x/y) | ||
(define (square-root x) | ||
(fixed-point (lambda (y) (/ (+ y (/ x y)) 2)) | ||
1.0)) | ||
(display (square-root 38)) |
This file contains 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
This file was deleted.
Oops, something went wrong.