Thursday, November 23, 2006

I ran in the afternoon, now it is dark outside in the afternoon, to the supermarket, and near my primary school, and it was nice with autumn leaves under street lights. Air is cold and it has fragrance like a snow will visit us soon. Today I wrote small JAVA program to calculate infinite series of numbers 1+1/3-1/5+1/7-1/9.... etc. That result multiplied with 4 should give something very near number PI=3.14159... So, I remember when I was in primary school I used CPC464 which ran on Z80 on only 4 MHz and I wrote that program in BASIC which was popular in those times. So, I remember that poor computer was running for hours and the error was still big. But now I put in loop number 1 billion, which was then unimaginable. It took several minutes to compute, while temperature of my 1.7 GHz Celeron rose from 35 C to 56 Celsius degrees! The result I got is 3.1415926545890476 and the error (difference from real number PI) is 9.992544569570327E-10 which means it is somewhere on tenth decimal place! Computers are miracles today, for a man just to count from 1 to billion, taking one second for each number and counting several hours a day would take entire life to count, and look what kind of calculations computer does easily in one billion loop! Here I am giving the listing of my program, and I am aware I could have written it better, but I was just playing today

public class priblizanPI { public static void main (String varg[]) { double pip, m, q=0; double n, sn=0; System.out.println("value error"); for (n=0;n<1000000000;n++) { m=1/(1+2*(n+1)); sn=Math.pow((-1),n); q=q+(m*sn*(-1)); } pip=4*(1+q); System.out.println(pip+" "+(pip-Math.PI)); }}


online college search