Alexander Bass

Math Notes 26

On Newton’s Method

Newton’s method allows finding the ‘root’ of a function (where it is zero), given conditions expressed in the wikipedia article no doubt.

More than this however, it can be used to find the inverse of a function. The common example is 2 . If you know x where x22=0 , then you know 2 .

The rough gist of the algorithm is as follows.

  1. Take a function like f(x)=x22
  2. Make an arbitrary guess on the value of x where f(x)=0 , g0
  3. Evaluate f(x) at g0 and find the line tangent to f(x) at g0
  4. Find the x-intercept of the tangent line. This x-intercept value is g1
  5. Repeat steps 2…5 (incrementing n throughout) until a satisfactory precision is obtained.

Algebraically, we start with the function and its derivative:

f(x)=x22f(x)=2x

And make a guess g0 and create the tangent line at that guess location on f(x)

y=f(g0)x+b

find b by evaluating at g0 :

f(g0)g0+b=f(g0) b=f(g0)f(g0)g0

Which finishes the line equation as:

y=f(g0)x+f(g0)f(g0)g0

Next, find the x-coordinate by evaluating at y=0

0=f(g0)x+f(g0)f(g0)g0f(g0)g0f(g0)=f(g0)xg0f(g0)f(g0)=x

As stated above, this x value is actually g1 , or generally

gn+1=gnf(gn)f(gn)

Going back the case of 2 , we substitute in the function

gn+1=gngn222gn

With gn=5 we see the first four approximations as:

g0=5g1=2.7g21.7204g31.4415g41.4145

Generally…

This process is easily generalized to finding inverses instead of roots — just as in the 2 example.

f(x) was previously defined as x22 , but more generically is described as f(x)=x2 . Then, inside the recursive equation, the 2 is placed outside the function

gn+1=gnf(gn)2f(gn)

The above gn+1 approximates f1(2) . the 2 is replaced with some constant c to find f1(c) :

The generic case for c then is:

gn+1=gngn2c2gn

Or

gn+1=gngn2c2gnlimngn=c

One way to loosely verify this is to: consider that when n approaches , the differences between gn and gn+1 will grow increasingly smaller (assuming the limit does indeed converge) and indeed will be come so close that we can consider them to be equal. So, we set gn+1=gn=x and solve:

x=xx2c2xx2c2x=0x2=cx=c

Other inverses

This method can be extended to other functions. Some examples:

ln(x)gn+1=gn1+xegnlog2(x)gn+1=gn1+x2gnln(2)xgn+1=gngn+x

Approximate Functions

By expanding the recursion a few steps, we can create an obnoxious approximation for ln(x) :

ln(x)xe1x+xexe1xx+2+xexe1xxexe1xx+2x+3+x4

And one for x :

x0.0625x4+1.75x3+4.375x2+1.75x+0.06250.5x3+3.5x2+3.5x+0.5

These examples were generated with the Python library SymPy. (I got exhausted of writing it by hand around third recursion)

View Code
from sympy import symbols, simplify, print_latex

x = symbols("x")

expr = 1
for i in range(0, 3):
    expr = 0.5 * expr + x / (2 * expr)

print_latex(simplify(expr))

Arccos and π

Suppose f(x)=sin(x) , then f(x)=0 when x=π . (or suppose f(x)=cos(x)+1 , then f(x)=0 when x=π .)

limngn=πwhereg0=3gn+1=gntan(gn)

Which gives π accurate to 100 digits in only 5 iterations.

View Code
from sympy import N, tan, pi

expr = 3
for i in range(0, 5):
    expr = expr - tan(expr)

print(N(expr, 100))
print(N(pi - expr, 100))

Despite this method’s remarkable rate of convergence, it’s dependence of the tangent function makes it less useful. Internally, any computation using this method would require an ‘infinite’ series (or some other approximation) of tan(x) . At which point I’m certain there’s a more direct way to compute it.

Nonetheless it remains a neat calculator trick to amuse mathematically included folks

Proof that π is rational (joke)

318π999.0366317π208341.0000081630294π1980127.0000017995207π3126535.0000011
View Code
from sympy import N, pi, floor
best = (10000, 1)

for i in range(1, 1_000_000):
    val = N(pi * i, 100)
    lz = val - floor(val)
    print(i, lz, val)
    lz = lz.evalf()
    if lz < best[0]:
        best = (lz, i)

print(best)

If I were to trust google’s calculator… then I’d say π is rational.