-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.40.scm
More file actions
38 lines (29 loc) · 763 Bytes
/
Copy path1.40.scm
File metadata and controls
38 lines (29 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(define (cube x)
(* x x x))
(define tolerance 0.00001)
(define (fixed-point f first-guess)
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance))
(define (try guess)
(let ((next (f guess)))
(if (close-enough? guess next)
next
(try next))))
(try first-guess))
(define dx 0.00001)
(define (deriv g)
(lambda (x)
(/ (- (g (+ x dx)) (g x))
dx)))
(define (newton-transform g)
(lambda (x)
(- x (/ (g x) ((deriv g) 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)))
(newtons-method (cubic 0 0 -8) 1)
(newtons-method (cubic 1 2 3) 1)