Functions
This module contains the algorithms for the nonlinear equations lab.
The materials follow Miranda and Fackler (2004, [MF04]) (Chapter 3). The python code draws on Romero-Aguilar (2020, [RA20]).
- labs.nonlinear_equations.nonlinear_algorithms.bisect(f, a, b, tolerance=1.5e-08)[source]
Apply bisect method to root finding problem.
Iterative procedure to find the root of a continuous real-values function
defined
on a bounded interval of the real line. Define interval
that is known to contain
or bracket the root of
(i.e. the signs of
and
must differ).
The given interval
is then repeatedly bisected into subintervals of equal length.
Each iteration, one of the two subintervals has endpoints of different signs (thus containing
the root of
) and is again bisected until the size of the subinterval containing the
root reaches a specified convergence tolerance.- Parameters
f (callable) – Continuous, real-valued, univariate function
.a (int or float) – Lower bound
for
.b (int or float) – Upper bound
for
. Select
and
so
that
has different sign than
.tolerance (float) – Convergence tolerance.
- Returns
x – Solution to the root finding problem within specified tolerance.
- Return type
float
Examples
>>> x = bisect(f=lambda x : x ** 3 - 2, a=1, b=2)[0] >>> round(x, 4) 1.2599
- labs.nonlinear_equations.nonlinear_algorithms.fischer(u, v, sign)[source]
Define Fischer’s function.

- Parameters
u (float) –
v (float) –
sign (float or int) – Gives sign of equation. Should be either 1 or -1.
- Returns
- Return type
callable
- labs.nonlinear_equations.nonlinear_algorithms.fixpoint(f, x0, tolerance=0.0001)[source]
Compute fixed point using function iteration.
- Parameters
f (callable) – Function
.x0 (float) – Initial guess for fixed point (starting value for function iteration).
tolerance (float) – Convergence tolerance (tolerance < 1).
- Returns
x – Solution of function iteration.
- Return type
float
Examples
>>> import numpy as np >>> x = fixpoint(f=lambda x : x**0.5, x0=0.4, tolerance=1e-10)[0] >>> np.allclose(x, 1) True
- labs.nonlinear_equations.nonlinear_algorithms.funcit(f, x0=2)[source]
Apply function iteration using the fixpoint method.
- labs.nonlinear_equations.nonlinear_algorithms.newton_method(f, x0, tolerance=1.5e-08)[source]
Apply Newton’s method to solving nonlinear equation.
Solve equation using successive linearization, which replaces the nonlinear problem by a sequence of linear problems whose solutions converge to the solution of the nonlinear problem.
- Parameters
f (callable) – (Univariate) function
.x0 (float) – Initial guess for the root of
.tolerance (float) – Convergence tolerance.
- Returns
xn – Solution of function iteration.
- Return type
float