Problem : Finding roots with Newton-Raphson method

Newton's method is a way to find roots of any continuos function, e.g. to find an \(x\) where \(f(x)=0\). The method starts of with some guess, \(x_i\) and in each iteration the guess is improved unless \(-\epsilon < f(x_i) < \epsilon\). Improvement is done as: \[ x_{i+1}=x_i - \frac{f(x_i)}{f'(x_i)}\]

When \(f(x)=x^n-A\) what we find x as root \(f(x)=0\) is \(x^n=A\), ie. nth root of \(A\). Since \(f'(x)=n\dot x^{n-1}\), the iteration becomes \[ x_{i+1}=x_i - \frac{x_i^n-A}{n\cdot x^{n-1}}\]

The initial guess, \(x_0\) is usually taken as 1.

solution

    (define (Newton a n xi e)
      (cond
        ((< (abs (- (expt xi n) a)) e) xi)
        (else (Newton a n (- xi (/ (- (expt xi n) a) (* n (expt xi (- n 1))))) e))))

    (Newton 2 2 1 0.01)
    (Newton 27 3 1 0.01)