SICP exercise 1.08

From Drewiki

Jump to: navigation, search

Problem

Newton's method for cube roots is based on the fact that if y is an approximation to the cube root of x, then a better approximation is given by the value

\frac{{x}/{y^2} + 2y}{3}

Use this formula to implement a cube-root procedure analogous to the square-root procedure from section 1.1.7 of the text.

Solution

Here's a straightforward solution to the problem.

 

Tests

 

Output:

2.0000049116755


 

Output:

3.00000054106418


 

Output:

4.00001744951074


 

Output:

5.00000000028793


 

Output:

4.64159011104646
Personal tools