Learn R Programming

AirScreen (version 0.1.0)

newton: Newton-Raphson root finder

Description

Newton-Raphson root finder

Usage

newton(f, fp, x, tol = 0.001, m = 100)

Value

The estimated root.

Arguments

f

Function whose root is sought.

fp

Derivative function of f.

x

Numeric starting value.

tol

Convergence tolerance (default 1e-3).

m

Maximum number of iterations (default \(100\)).

Details

Iterates \(x_{new} = x - f(x)/f'(x)\) until the change is below tol or m iterations are reached (then issues a warning).

Examples

Run this code
# Solve x^2 - 2 = 0
newton(function(x) x^2 - 2, function(x) 2*x, 1)

Run the code above in your browser using DataLab