Finding the Perfect Curve: Newton-Raphson and Pen Turning
Watch a turner at the lathe and you’ll see something remarkable: they don’t carve the final shape in one pass. Instead, they make small, calculated cuts, constantly measuring and adjusting, each pass bringing them closer to the perfect curve. The wood reveals its intentions gradually—too aggressive and you’ll tear the grain; too timid and you’ll never reach your goal.
This dance of iterative refinement mirrors one of computing’s most elegant numerical methods. Newton-Raphson doesn’t solve equations by brute force—it makes educated guesses, then uses calculus to figure out which direction to move next.
(define (newton-raphson f df x0 tolerance)
(let ((x1 (- x0 (/ (f x0) (df x0)))))
(if (< (abs (- x1 x0)) tolerance)
x1
(newton-raphson f df x1 tolerance))))
;; Find where x² - 2 = 0 (square root of 2)
(newton-raphson (lambda (x) (- (* x x) 2))
(lambda (x) (* 2 x))
1.0
0.0001)
Scheme’s recursive elegance captures the mathematical purity—each iteration builds upon the last, like growth rings in wood.
import java.util.function.Function;
class NewtonDemo {
public static double newtonRaphson(Function<Double, Double> f,
Function<Double, Double> df,
double x0, double tolerance) {
double x = x0;
while (true) {
double fx = f.apply(x);
double xNew = x - fx / df.apply(x);
if (Math.abs(xNew - x) < tolerance) return xNew;
x = xNew;
}
}
public static void main(String[] args) {
double root = newtonRaphson(x -> x * x - 2, x -> 2 * x, 1.0, 0.0001);
System.out.printf("%.5f%n", root);
}
}
Java’s imperative approach feels more like the turner’s hands—deliberate, controlled, with explicit state management. Both languages find the same truth: √2 ≈ 1.41421.
The method’s genius lies in using the derivative—the tangent line—to predict where the function crosses zero. Just as a skilled turner reads the wood grain to anticipate the next cut, Newton-Raphson reads the mathematical landscape through its slope. Sometimes it converges in three iterations; sometimes it oscillates. Like working with difficult wood, success demands respect for the material’s nature.