math4610

Routine Name: FixedPointIteration

Author: David Merkley

Language: Python

Description/Purpose: Approximates the root of a function

Input: a function f, starting point, tolerance, scaling constant, and a maximum number of iterations.

Output: An approximate root.

Implementation/Code:

def fixedPointIter(fx, tol=1e-10, x0=0, epsi=1, maxitter=1e10):
    x1 = x0 - epsi * fx(x0)
    counter = 0
    while counter in range(int(maxitter)):
        if abs(x1 - x0) < tol:
            return x0
        x0 = x1
        x1 = x1 - epsi * fx(x1)
        counter = counter + 1