fzero
Builtin index · Signal processing
result = fzero(f, a, b, [tol=1e-10], [max_iter=100])
Input: f, a, b, tol, max_iter · Output: result
What it is
f: a string naming a user-defined function of one number, returning a number; a, b: numbers, the bracket endpoints where f changes sign; tol/max_iter (optional numbers).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = fzero(f, a, b, [tol=1e-10], [max_iter=100]) | f string or numberf: a string naming a user-defined function of one number, returning a number.a numbera, b: numbers, the bracket endpoints where f changes sign.b numbera, b: numbers, the bracket endpoints where f changes sign.tol number, optional (default 1e-10)tol/max_iter (optional numbers).max_iter number, optional (default 100)tol/max_iter (optional numbers). | result number | Returns a single number, the root. Brent's method: robust root finding given a bracket [a,b], no derivative needed. |
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
and general minimization. Only a user-defined function (by name, the same convention pmap/spawn use) can be the target of any of these — not a builtin. fzero(f, a, b, [tol=1e-10], [max_iter=100]) — Brent's method: robust root finding (guaranteed convergence given a bracket [a,b] where f changes sign), no derivative needed. The "something better than plain bisection" choice.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.