Tuesday, January 17, 2006

Vieta's Formula

Vieta's Formula for Pi
We continue the discussion on approximating Pi by calculating the areas of a circle using inscribed and circumscribed regular polygons. We illustrate Vieta's formula, developed in 1593, the oldest exact result derived for Pi.
The Formula
Vieta's formula expresses as an infinite product of nested square roots.
Here is the implementation:public class Vieta {
public static double rhs(int n) {
double result = 0;
double rhs_1 = 0;
double rhs_2 = 0;
for (int i = 1; i <= n; ++i) {
if (i == 1) {
result = Math.sqrt(0.5 + 0.5 * Math.sqrt(0.5));
rhs_1 = result;
rhs_2 = result;
} else if (i == 2) {
result = rhs_1 * Math.sqrt(0.5 + 0.5 * rhs_1);
rhs_1 = result;
} else {
result = rhs_1 * Math.sqrt(0.5 + 0.5 * rhs_1 / rhs_2);
rhs_2 = rhs_1;
rhs_1 = result;
}
}
return result;
}
}
I also wrote a Applet for calculating PI.
http://www.myjavaserver.com/~torotime/vieta_formula.html
However,once I finished this applet, I have a new ideal that I can write it in javascript for more portable result...
applet sight~~~


No comments: