newton: Newton's method

Description Usage Arguments Details Value See Also Examples

View source: R/newton.R

Description

Use Newton's method to find real roots

Usage

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

Arguments

f

function to integrate

fp

function representing the derivative of f

x

an initial estimate of the root

tol

the error tolerance

m

the maximum number of iterations

Details

Newton's method finds real roots of a function, but requires knowing the function derivative. It will return when the interval between them is less than tol, the error tolerance. However, this implementation also stops after m iterations.

Value

the real root found

See Also

Other optimz: bisection, goldsect, gradient, hillclimbing, sa, secant

Examples

1
2
3
f <- function(x) { x^3 - 2 * x^2 - 159 * x - 540 }
fp <- function(x) {3 * x^2 - 4 * x - 159 }
newton(f, fp, 1)

cmna documentation built on June 20, 2017, 9:08 a.m.