An archive of Mark's Spring 2018 Numerical Analysis course.

Section 2.2 Question 16

Sampson

Use a fixed point iteration method to find an approximation of \sqrt{3} that is accurate to within 10^{-4}. What function and initial value did you use?

Sampson

I used the function:

F(x) = \frac{3}{(2{\times}x)+\frac{x}{2}}

Here is what the function looks like when plotted with f(x) = x and the subsequent code I used to attain the plot:

import numpy as np
from matplotlib import pyplot as plt

def F(x): return 3/(2*x)+x/2
def f(x): return (1/2)*(x+(3/x))-x

x = np.linspace(-2,3,100)
y = F(x)
plt.plot(x,y)
plt.plot(x,x)
plt.ylim(-2,3)
plt.grid(True)
plt.show() 

2_Question16

Then by iterating F(x) we can attain an approximation for \sqrt{3} within 10^{-4}. My initial point was x_0 = 1.

x = 1
cnt = 0
while np.abs(f(x))>10**-4 and cnt <100:
    x = F(x)
    cnt = cnt + 1
x,cnt

#Out: (1.7321428571428572, 3)
mark

Hmm… When it says “what function did you use”, I think they mean that f should be the function whose root you’re trying to approximate. I think your f is the Newton method iteration function.