Why does one approximation of pi equation decrease error, while the other increases it with more iterations?

95 Views Asked by At

When approximating pi, these two equations give radically diffrent relative errors? is this due to floating point arithmetic or the equations themselves?

They remain relatively equal for the first 14 iterations however after that Equation 1 relative error increases while the other lowers. The initial value y1=2.0, and iterates to k=30. This culminates in equation 1 error getting worse till it equates itself to 0 rather than 3.141....

Is this due to precision or the equations themselves, and if the equations why?

enter image description here enter image description here

1

There are 1 best solutions below

2
On

If $y_k$ is reasonable sized, say about $\pi$, $\sqrt {(1-[2^{-k}y_k]^2)}$ suffers from cancellation as $k$ gets large. The square brackets are about $10\cdot 2^{-2k}$, which in a $64$ bit float with $53$ bits of precision will be completely lost by the time $k=30$. The square root will then be $1$ and when you subtract it from $1$ you get $0$, which is why the iteration converges on $0$. The second one, which adds the square root to $1$ will stop changing when the square root becomes a solid $1$, but will leave $y_k$ the same.