Successive substitution

Successive substitution

References:

def f(x):
    return 1.0/x - 0.8 + x

x1 = 2
err = 1e10
while err > 1e-5:
    x2 = f(x1)
    err = abs(x1 - x2)
    x1 = x2

x1
1.250005085698445
def g(x):
    return x**2 + x - 2

x1 = 2
x2 = g(x1)

err = 1e10
while err > 1e-5:
    s = (g(x2) - g(x1))/(x2 - x1)
    t = 1.0/(1.0 - s)
    x3 = t * g(x2) + (1.0 - t) * x2
    err = abs(x3 - x2)
    x1 = x2
    x2 = x3

x2
1.4142135625159447
x1 = 2
x2 = f(x1)

err = 1e10
while err > 1e-5:
    s = (f(x2) - f(x1))/(x2 - x1)
    t = 1.0/(1.0 - s)
    x3 = t * f(x2) + (1.0 - t) * x2
    err = abs(x3 - x2)
    x1 = x2
    x2 = x3

x2
1.2499999999992144

Successive substitution

References:

def f(x):
    return 1.0/x - 0.8 + x

x1 = 2
err = 1e10
while err > 1e-5:
    x2 = f(x1)
    err = abs(x1 - x2)
    x1 = x2

x1
1.250005085698445
def g(x):
    return x**2 + x - 2

x1 = 2
x2 = g(x1)

err = 1e10
while err > 1e-5:
    s = (g(x2) - g(x1))/(x2 - x1)
    t = 1.0/(1.0 - s)
    x3 = t * g(x2) + (1.0 - t) * x2
    err = abs(x3 - x2)
    x1 = x2
    x2 = x3

x2
1.4142135625159447
x1 = 2
x2 = f(x1)

err = 1e10
while err > 1e-5:
    s = (f(x2) - f(x1))/(x2 - x1)
    t = 1.0/(1.0 - s)
    x3 = t * f(x2) + (1.0 - t) * x2
    err = abs(x3 - x2)
    x1 = x2
    x2 = x3

x2
1.2499999999992144