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?
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?
I used the function:
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()
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)
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.