# [Scheme] Square root (newton method)

Page 1 of 1

## 0 Replies - 347 Views - Last Post: 06 October 2006 - 11:31 AM

### #1 William_Wilson Reputation: 207
• Posts: 4,812
• Joined: 23-December 05

# [Scheme] Square root (newton method)

Posted 06 October 2006 - 11:31 AM

Description: provide a value to find root of, a guess as to its root and the precision to find such root.find a square root with the newton method
```;square, good-enough?, and improve are shared by both a and b versions
(define (square x) ( * x x))

(define (good-enough? guess x p)
(< (abs (- (square guess) x)) p))

(define (average x y)
(/ (+ x y) 2))

(define (improve guess x)
(average guess ( / x guess)))

(define (sqrt-iterationA guess x p count)
(if(good-enough? guess x p)
guess
(sqrt-iterationA (improve guess x) x p (+ count 1))))

(define (sqrtA x guess precision)
(sqrt-iterationA (* guess 1.0) x precision 0));ensure decimals
```

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }