Fixed point

What is the numerical solution of the fixed-point equation x = cos ( x ) x = \cos( x) , x R x \in \mathbb{R} ?

To calculate this, program a function fixedPoint(f, x) , which takes a function f and a starting value x as inputs and returns the fixed point y = f(y) as an output.

1
2
3
4
5
6
7
from math import *

def fixedPoint(f, x):
    # calculate fixed-point y = f(y)
    return y

print(fixedPoint(cos, 0.5))

Bonus question: Why does the algorithm work?


The answer is 0.7390851332151607.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Markus Michelmann
May 23, 2018

A common algorithm for solving nonlinear equations is the fixed point iteration. For this the following sequence is calculated x n = f ( x n 1 ) = f ( f ( f ( n times x 0 ) ) ) = ( f n ) ( x 0 ) , n N x_{n} = f(x_{n-1}) = \underbrace{f(f(\dots f(}_{n \text{ times}}x_0)\dots)) = (f^n)(x_0), \quad n \in \mathbb{N} where x 0 x_0 is a suitable starting value. When this sequence converges, we can break the iteration and have found our fixpoint. The fact that this sequence converges for the cosine can be proved by the Banach fixed point theorem. The criteria for convergence are accordingly:

  • Choose a closed interval I I with f ( I ) I f (I) \subset I
  • For all points x I x \in I is f ( x ) < 1 | f '(x) | <1

Then the fixed point iteration converges for a starting value x 0 I x_0 \in I . These criteria are fulfilled in the case f ( x ) = cos ( x ) f(x) = \cos(x) and I = [ 0 , 1 ] I = [0,1] .

With a few lines of code you can therefore solve a non-linear equation, if the starting value has been chosen appropriately and the fixed point is stable:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from math import *

def fixedPoint(f, x):
    y = f(x)
    while(y != x):
        x = y
        y = f(x)
    return y

print(fixedPoint(cos, 0.5))

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...