next up previous contents
Next: Vectors und Matrices (1) Up: Variables Previous: Exercise 3 (Variables)

Exercise 4 (Variables)

Calculate some elements of the recursively defined sequence

\begin{displaymath}x_0 = 1 \hspace*{2cm} x_{n+1}=\frac{1}{2}(x_n+\frac{3}{x_n}) \end{displaymath}

When does this sequence approach its limit $\sqrt{3}$ to within 2*eps?

Solution:

>> x=1
x = 1
>> x=1/2*(x+3/x); x-sqrt(3)   % n= 1
ans = 0.26795
>> x=1/2*(x+3/x); x-sqrt(3)   % n= 2
ans = 1.7949E-2
>> x=1/2*(x+3/x); x-sqrt(3)   % n= 3
ans = 9.205E-5
>> x=1/2*(x+3/x); x-sqrt(3)   % n= 4
ans = 2.4459E-9
>> x=1/2*(x+3/x); x-sqrt(3)   % n= 5
ans = 0                       % Bingo
0


Helmut Dersch
2009-03-15