-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex_1_045.scm
34 lines (27 loc) · 868 Bytes
/
ex_1_045.scm
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
(define tolerance 0.00001)
(define (repeated function n)
(define (repeated_iterative f n)
(if (= n 1)
(lambda (x) (f x))
(repeated_iterative (lambda (x) ( function (f x)))
(- n 1))))
(repeated_iterative function n))
(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 (average-damp f)
(lambda (x) (/ (+ x (f x))
2)))
(define (n-root x n)
(fixed-point (repeated (average-damp (lambda (y)
(/ x
(expt y (- n 1)))))
(+ (remainder n 4) 1))
1.0))
(n-root 100 10)