root_finding

quantecon.optimize.root_finding.newton[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:
func : callable 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.

x0 : float

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

fprime : callable and jitted

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

args : tuple, optional(default=())

Extra arguments to be used in the function call.

tol : float, optional(default=1.48e-8)

The allowable error of the zero value.

maxiter : int, optional(default=50)

Maximum number of iterations.

disp : bool, optional(default=True)

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

Returns:
results : namedtuple

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[source]

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

func, fprime, fprime2 must be jitted via Numba.

Parameters:
func : callable 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.

x0 : float

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

fprime : callable and jitted

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

fprime2 : callable and jitted

The second order derivative of the function

args : tuple, optional(default=())

Extra arguments to be used in the function call.

tol : float, optional(default=1.48e-8)

The allowable error of the zero value.

maxiter : int, optional(default=50)

Maximum number of iterations.

disp : bool, optional(default=True)

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

Returns:
results : namedtuple

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[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:
func : callable 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.

x0 : float

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

args : tuple, optional(default=())

Extra arguments to be used in the function call.

tol : float, optional(default=1.48e-8)

The allowable error of the zero value.

maxiter : int, optional(default=50)

Maximum number of iterations.

disp : bool, optional(default=True)

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

Returns:
results : namedtuple

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.bisect[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:
f : jitted and callable

Python function returning a number. f must be continuous.

a : number

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

b : number

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

args : tuple, optional(default=())

Extra arguments to be used in the function call.

xtol : number, 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.

rtol : number, 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.

maxiter : number, optional(default=100)

Maximum number of iterations.

disp : bool, optional(default=True)

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

Returns:
results : namedtuple
quantecon.optimize.root_finding.brentq[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:
f : jitted and callable

Python function returning a number. f must be continuous.

a : number

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

b : number

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

args : tuple, optional(default=())

Extra arguments to be used in the function call.

xtol : number, 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.

rtol : number, 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.

maxiter : number, optional(default=100)

Maximum number of iterations.

disp : bool, optional(default=True)

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

Returns:
results : namedtuple