180
7 Solving Nonlinear Algebraic Equations
# Return x and y values
return [(x[i], y[i]) for i in minima], \
[(x[i], y[i]) for i in maxima]
The max and min functions are standard Python functions for finding the maximum
and minimum element of a list or an object that one can iterate over with a for loop.
An application to f (x) = e −x 2 cos(4x) looks like
def demo():
from numpy import exp, cos
minima, maxima = brute_force_optimizer(
lambda x: exp(-x**2)*cos(4*x), 0, 4, 1001)
print(’Minima:\n’, minima)
print(’Maxima:\n’, maxima)
Running the program gives
Minima:
[(0.70000000000000007, -0.5772302750838405), (2.1520000000000001,
-0.0066704807422565023), (3.6600000000000001, -7.3338267339366542e-07)]
Maxima:
[(1.4159999999999999, 0.10965467991643564), (2.8999999999999999,
0.00012651823896373234), (0.0, 1.0)]
7.1.3 Model Problem for Algebraic Equations
We shall consider the very simple problem of finding the square root of 9. That is,
we want to solve x 2 = 9, but will (for simplicity) seek only the positive solution.
Knowing the solution beforehand, allows us to easily investigate how the numerical
method (and the implementation of it) performs in the search for a solution. The
f (x) function that corresponds to the equation x 2 = 9 is
f (x) = x
2
− 9 .
Our interval of interest for solutions will be [0, 1000] (the upper limit here is chosen
somewhat arbitrarily).
In the following, we will present several efficient and accurate methods for solving nonlinear algebraic equations, both single equation and systems of equations.
The methods all have in common that they search for approximate solutions. The
methods differ, however, in the way they perform the search for solutions. The idea
for the search influences the efficiency of the search and the reliability of actually
finding a solution. For example, Newton’s method is very fast, but not reliable, while
the bisection method is the slowest, but absolutely reliable. No method is best at all
problems, so we need different methods for different problems.
7 Solving Nonlinear Algebraic Equations
# Return x and y values
return [(x[i], y[i]) for i in minima], \
[(x[i], y[i]) for i in maxima]
The max and min functions are standard Python functions for finding the maximum
and minimum element of a list or an object that one can iterate over with a for loop.
An application to f (x) = e −x 2 cos(4x) looks like
def demo():
from numpy import exp, cos
minima, maxima = brute_force_optimizer(
lambda x: exp(-x**2)*cos(4*x), 0, 4, 1001)
print(’Minima:\n’, minima)
print(’Maxima:\n’, maxima)
Running the program gives
Minima:
[(0.70000000000000007, -0.5772302750838405), (2.1520000000000001,
-0.0066704807422565023), (3.6600000000000001, -7.3338267339366542e-07)]
Maxima:
[(1.4159999999999999, 0.10965467991643564), (2.8999999999999999,
0.00012651823896373234), (0.0, 1.0)]
7.1.3 Model Problem for Algebraic Equations
We shall consider the very simple problem of finding the square root of 9. That is,
we want to solve x 2 = 9, but will (for simplicity) seek only the positive solution.
Knowing the solution beforehand, allows us to easily investigate how the numerical
method (and the implementation of it) performs in the search for a solution. The
f (x) function that corresponds to the equation x 2 = 9 is
f (x) = x
2
− 9 .
Our interval of interest for solutions will be [0, 1000] (the upper limit here is chosen
somewhat arbitrarily).
In the following, we will present several efficient and accurate methods for solving nonlinear algebraic equations, both single equation and systems of equations.
The methods all have in common that they search for approximate solutions. The
methods differ, however, in the way they perform the search for solutions. The idea
for the search influences the efficiency of the search and the reliability of actually
finding a solution. For example, Newton’s method is very fast, but not reliable, while
the bisection method is the slowest, but absolutely reliable. No method is best at all
problems, so we need different methods for different problems.
