newton
Builtin index · Signal processing
result = newton(f, fprime, x0, [tol=1e-12], [max_iter=100])
Input: f, fprime, x0, tol, max_iter · Output: result
What it is
f, fprime: strings naming user-defined functions of one number (the function and its derivative); x0: number, the starting guess; tol/max_iter (optional numbers).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = newton(f, fprime, x0, [tol=1e-12], [max_iter=100]) | f string or numberf, fprime: strings naming user-defined functions of one number (the function and its derivative).fprime string or numberf, fprime: strings naming user-defined functions of one number (the function and its derivative).x0 numberx0: number, the starting guess.tol number, optional (default 1e-12)tol/max_iter (optional numbers).max_iter number, optional (default 100)tol/max_iter (optional numbers). | result number | Returns a single number, the root. Newton's method: fast (quadratic convergence) when it works, but needs a derivative and can diverge from a poor starting guess, unlike fzero. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
f(x) := x^2 - 2
root = fzero("f", 0, 2) # Brent's method: needs a bracket
# [a,b] where f changes sign, always
# converges, no derivative needed
fprime(x) := 2*x
root2 = newton("f", "fprime", 1.0) # Newton's method: fast (quadratic
# convergence) when it works, but
# needs a derivative and can diverge
from numerics-dsp
How it works
newton(f, fprime, x0, [tol=1e-12], [max_iter=100]) — Newton's method: fast (quadratic convergence) when it works, but needs a derivative and can diverge from a poor starting guess, unlike fzero.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.