Section 1.6
The Newton Method
Lecture Video
Solving equations and finding inverse transformations using the Newton method
In science and engineering we often need to solve systems of equations.
If the equations are linear then linear algebra tells us a general method to solve them; these are now routinely applied to solve systems of millions of linear equations.
If the equations are nonlinear then things are less obvious. The main solution methods we know work by... reducing the nonlinear equations to a sequence of linear equations! They do this by approximating the function by a linear function and solving that to get a better solution, then repeating this operation as many times as necessary to get a sequence of increasingly better solutions. This is an example of an iterative algorithm.
A well-known and elegant method, which can be used in many different contexts, is the Newton method. It does, however, have the disadvantage that it requires derivatives of the function. This can be overcome using automatic differentiation techniques.
We will illustrate the Newton method using the ForwardDiff.jl
package to carry out automatic differentiation, but we will also try to understand what's going on "under the hood".
The Newton method in 1D
We would like to solve equations like
A point
The Newton method finds zeros, and hence solves the original equation.
The idea of the Newton method is to follow the direction in which the function is pointing! We do this by building a tangent line at the current position and following that instead, until it hits the
Let's look at that visually first:
n =
x₀ =
n =
x₀ =
Using symbolic calculations to understand derivatives and nonlinear maps
We can use Julia's new symbolic capabilities to understand what's going on with a nonlinear (polynomial) function.
Let's see what happens if we perturb a function
m =
When
The derivative gives the "linear part" of the function. ForwardDiff.jl
, and forward-mode automatic differentiation in general, effectively uses this (although not symbolically in this sense) to just propagate the linear part of each function through a calculation.
Mathematics of the Newton method
We can convert the idea of "following the tangent line" into equations as follows. (You can also do so by just looking at the geometry in 1D, but that does not help in 2D.)
Suppose we have a guess
Let's set
We want
If we are already "quite close" to the root then
and hence
so that
Now we can repeat so that
and in general
This is the Newton method in 1D.
Implementation in 1D
newton1D (generic function with 1 method)
1.414213562373095
1.4142135623730951
Symbolic derivative in 2D
Let's see what happens when we perturb by small amounts
p =
2×2 Matrix{Text{Num}}:
1.0 0.0
0.0 1.0
Newton for transformations in 2 dimensions
We want to find the inverse
We use the same idea as in 1D, but now in 2D:
where
Hence
Then we again construct the new approximation
In 2D we have an explicit formula for the inverse of the matrix.
Implementation in 2D
newton2D_step (generic function with 1 method)
Looks for x such that T(x) = 0
Remember that Newton is designed to look for roots, i.e. places where
Looks for x such that f(x) = y, i.e. f(x) - y = 0
inverse (generic function with 3 methods)
straight (generic function with 1 method)
standard_Newton (generic function with 3 methods)
T (generic function with 1 method)
α =
0.3
0.4
0.3
0.4
0.3
0.4
Appendix
expand (generic function with 1 method)