PI. That magic word that we were suddenly introduced to out of the blues in primary school.(22/7..lol)
The aim of this article is to describe some weird series I came across many years ago, while experimenting with different series.
I found that when there are certain positive integers for which:
If the integer is k: then
PI^k/constant = Summation(n ^ -k) from n=1 to n=infinity.

This series converge so rapidly..especially as the k becomes larger, that they become willing tools
in the computation of PI.
The [T, k] pairs are:

No doubt, the series gotten by substituting the first T,k values on the table is most familiar to everyone in the math. community!
Using the last pair of values on the table in the series, we get PI = 3.141592653589793 which is the highest possible accuracy available in the programming language(JAVA) which I used for the computation.
Question? how did those values come about?....not for me though..I am more of an experimental scientist than a theoretical one!
Below, I supply Java code that performs the computation:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package securechatengine.test;
import java.math.BigDecimal;
import java.math.MathContext;
The aim of this article is to describe some weird series I came across many years ago, while experimenting with different series.
I found that when there are certain positive integers for which:
If the integer is k: then
PI^k/constant = Summation(n ^ -k) from n=1 to n=infinity.

This series converge so rapidly..especially as the k becomes larger, that they become willing tools
in the computation of PI.
The [T, k] pairs are:
No doubt, the series gotten by substituting the first T,k values on the table is most familiar to everyone in the math. community!
Using the last pair of values on the table in the series, we get PI = 3.141592653589793 which is the highest possible accuracy available in the programming language(JAVA) which I used for the computation.
Question? how did those values come about?....not for me though..I am more of an experimental scientist than a theoretical one!
Below, I supply Java code that performs the computation:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package securechatengine.test;
import java.math.BigDecimal;
import java.math.MathContext;
/**
*
* @author JIBOYE, OLUWAGBEMIRO OLAOLUWA
*
*/
public class TestPI {
public BigDecimal calc(int terms,int power){
BigDecimal acc = new BigDecimal(0.00,MathContext.DECIMAL128);
BigDecimal one = new BigDecimal(1.0,MathContext.DECIMAL128);
BigDecimal PI = new BigDecimal(Math.PI,MathContext.DECIMAL128);
for(double i=1;i<=terms;i++){
BigDecimal bd = new BigDecimal(i, MathContext.DECIMAL128).pow(power,MathContext.DECIMAL128);
System.out.println( "bd = "+bd );
acc = acc.add(one.divide(bd,MathContext.DECIMAL128));
System.out.println( "acc = "+acc );
}
return PI.pow(power,MathContext.DECIMAL128).divide(acc,MathContext.DECIMAL128);
}
public BigDecimal calcInv(int terms,int power){
BigDecimal acc = new BigDecimal(0.00,MathContext.DECIMAL128);
BigDecimal one = new BigDecimal(1.0,MathContext.DECIMAL128);
BigDecimal PI = new BigDecimal(Math.PI,MathContext.DECIMAL128);
for(double i=1;i<=terms;i++){
BigDecimal bd = new BigDecimal(i, MathContext.DECIMAL128).pow(power,MathContext.DECIMAL128);
System.out.println( "bd = "+bd );
acc = i%2==0 ? acc.add(one.divide(bd,MathContext.DECIMAL128)) : acc.subtract(one.divide(bd,MathContext.DECIMAL128));
System.out.println( "acc = "+acc );
}
return PI.pow(power,MathContext.DECIMAL128).divide(acc,MathContext.DECIMAL128);
}
/**
*
* @param terms The number of terms of the series
* @param power The power to use..Must be one of the magic numbers!
* Either 2,4,6,8,10 or 14
* @return the value of PI
*/
public double calcPI(int terms,double power){
double constant = getPiConstantEval(power);
double acc = 0;
for(double i=1;i<=terms;i++){
double bd = Math.pow(i,power);
acc += (1.0/bd);
}
double prod = constant * acc;
return Math.pow(prod,1/power);
}
public static void main(String[] args) {
System.out.println( "Real PI = "+Math.PI );
TestPI tpi = new TestPI();
// System.out.println( tpi.calc(200, 10).toString() );
System.out.println( "Computed PI = " + tpi.calcPI(15, 14) );
}
/**
* This code gives the constant T for a given power
* that we can use to compute PI.
* You can rewrite this method to return an int or double
* as you wish.
*/
public static double getPiConstantEval(double power){
switch((int)power){
case 2:
return 6.0;
case 4:
return 90.0;
case 6:
return 945.0;
case 8:
return 9450.0;
case 10:
return 93555.0;
case 14:
return 9121612.5;
default:
throw new ArithmeticException("Lol..They are magic numbers for PI dear! use them or crash it");
}
}
public static BigDecimal getPiConstantEvalBigDec(double power){
switch((int)power){
case 2:
return new BigDecimal(6, MathContext.DECIMAL128);
case 4:
return new BigDecimal(90, MathContext.DECIMAL128);
case 6:
return new BigDecimal(945, MathContext.DECIMAL128);
case 8:
return new BigDecimal(9450, MathContext.DECIMAL128);
case 10:
return new BigDecimal(93555, MathContext.DECIMAL128);
case 14:
return new BigDecimal(9121612.5, MathContext.DECIMAL128);
default:
throw new ArithmeticException("Lol..They are magic numbers for PI dear! use them or crash it");
}
}
}
No comments:
Post a Comment