# root_finding¶

quantecon.optimize.root_finding.bisect(f, a, b, args=(), xtol=2e-12, rtol=8.881784197001252e-16, maxiter=100, disp=True)[source]

Find root of a function within an interval adapted from Scipy’s bisect.

Basic bisection routine to find a zero of the function f between the arguments a and b. f(a) and f(b) cannot have the same signs.

f must be jitted via numba.

Parameters:
fjitted and callable

Python function returning a number. f must be continuous.

anumber

One end of the bracketing interval [a,b].

bnumber

The other end of the bracketing interval [a,b].

argstuple, optional(default=())

Extra arguments to be used in the function call.

xtolnumber, optional(default=2e-12)

The computed root `x0` will satisfy ```np.allclose(x, x0, atol=xtol, rtol=rtol)```, where `x` is the exact root. The parameter must be nonnegative.

rtolnumber, optional(default=4*np.finfo(float).eps)

The computed root `x0` will satisfy ```np.allclose(x, x0, atol=xtol, rtol=rtol)```, where `x` is the exact root.

maxiternumber, optional(default=100)

Maximum number of iterations.

dispbool, optional(default=True)

If True, raise a RuntimeError if the algorithm didn’t converge.

Returns:
resultsnamedtuple
quantecon.optimize.root_finding.brentq(f, a, b, args=(), xtol=2e-12, rtol=8.881784197001252e-16, maxiter=100, disp=True)[source]

Find a root of a function in a bracketing interval using Brent’s method adapted from Scipy’s brentq.

Uses the classic Brent’s method to find a zero of the function f on the sign changing interval [a , b].

f must be jitted via numba.

Parameters:
fjitted and callable

Python function returning a number. f must be continuous.

anumber

One end of the bracketing interval [a,b].

bnumber

The other end of the bracketing interval [a,b].

argstuple, optional(default=())

Extra arguments to be used in the function call.

xtolnumber, optional(default=2e-12)

The computed root `x0` will satisfy ```np.allclose(x, x0, atol=xtol, rtol=rtol)```, where `x` is the exact root. The parameter must be nonnegative.

rtolnumber, optional(default=4*np.finfo(float).eps)

The computed root `x0` will satisfy ```np.allclose(x, x0, atol=xtol, rtol=rtol)```, where `x` is the exact root.

maxiternumber, optional(default=100)

Maximum number of iterations.

dispbool, optional(default=True)

If True, raise a RuntimeError if the algorithm didn’t converge.

Returns:
resultsnamedtuple
quantecon.optimize.root_finding.newton(func, x0, fprime, args=(), tol=1.48e-08, maxiter=50, disp=True)[source]

Find a zero from the Newton-Raphson method using the jitted version of Scipy’s newton for scalars. Note that this does not provide an alternative method such as secant. Thus, it is important that fprime can be provided.

Note that func and fprime must be jitted via Numba. They are recommended to be njit for performance.

Parameters:
funccallable and jitted

The function whose zero is wanted. It must be a function of a single variable of the form f(x,a,b,c…), where a,b,c… are extra arguments that can be passed in the args parameter.

x0float

An initial estimate of the zero that should be somewhere near the actual zero.

fprimecallable and jitted

The derivative of the function (when available and convenient).

argstuple, optional(default=())

Extra arguments to be used in the function call.

tolfloat, optional(default=1.48e-8)

The allowable error of the zero value.

maxiterint, optional(default=50)

Maximum number of iterations.

dispbool, optional(default=True)

If True, raise a RuntimeError if the algorithm didn’t converge

Returns:
resultsnamedtuple

A namedtuple containing the following items:

```root - Estimated location where function is zero.
function_calls - Number of times the function was called.
iterations - Number of iterations needed to find the root.
converged - True if the routine converged
```
quantecon.optimize.root_finding.newton_halley(func, x0, fprime, fprime2, args=(), tol=1.48e-08, maxiter=50, disp=True)[source]

Find a zero from Halley’s method using the jitted version of Scipy’s.

func, fprime, fprime2 must be jitted via Numba.

Parameters:
funccallable and jitted

The function whose zero is wanted. It must be a function of a single variable of the form f(x,a,b,c…), where a,b,c… are extra arguments that can be passed in the args parameter.

x0float

An initial estimate of the zero that should be somewhere near the actual zero.

fprimecallable and jitted

The derivative of the function (when available and convenient).

fprime2callable and jitted

The second order derivative of the function

argstuple, optional(default=())

Extra arguments to be used in the function call.

tolfloat, optional(default=1.48e-8)

The allowable error of the zero value.

maxiterint, optional(default=50)

Maximum number of iterations.

dispbool, optional(default=True)

If True, raise a RuntimeError if the algorithm didn’t converge

Returns:
resultsnamedtuple

A namedtuple containing the following items:

```root - Estimated location where function is zero.
function_calls - Number of times the function was called.
iterations - Number of iterations needed to find the root.
converged - True if the routine converged
```
quantecon.optimize.root_finding.newton_secant(func, x0, args=(), tol=1.48e-08, maxiter=50, disp=True)[source]

Find a zero from the secant method using the jitted version of Scipy’s secant method.

Note that func must be jitted via Numba.

Parameters:
funccallable and jitted

The function whose zero is wanted. It must be a function of a single variable of the form f(x,a,b,c…), where a,b,c… are extra arguments that can be passed in the args parameter.

x0float

An initial estimate of the zero that should be somewhere near the actual zero.

argstuple, optional(default=())

Extra arguments to be used in the function call.

tolfloat, optional(default=1.48e-8)

The allowable error of the zero value.

maxiterint, optional(default=50)

Maximum number of iterations.

dispbool, optional(default=True)

If True, raise a RuntimeError if the algorithm didn’t converge.

Returns:
resultsnamedtuple

A namedtuple containing the following items:

```root - Estimated location where function is zero.
function_calls - Number of times the function was called.
iterations - Number of iterations needed to find the root.
converged - True if the routine converged
```