From cecf806d488937c5917488fbdb0428f3419987c3 Mon Sep 17 00:00:00 2001 From: AKS1996 Date: Sat, 21 Oct 2017 14:18:15 +0000 Subject: [PATCH] Guass Legendre Algorithm for approximation of pi --- Others/GuassLengendre.java | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Others/GuassLengendre.java diff --git a/Others/GuassLengendre.java b/Others/GuassLengendre.java new file mode 100644 index 00000000..289516ae --- /dev/null +++ b/Others/GuassLengendre.java @@ -0,0 +1,44 @@ +import java.lang.Math; +/* + * author: @AKS1996 + * Guass Legendre Algorithm + * ref https://en.wikipedia.org/wiki/Gauss–Legendre_algorithm + * + */ + +public class GuassLegendre { + + public static void main(String[] args) { + for(int i=1;i<=3;++i) + System.out.println(pi(i)); + + } + + static double pi(int l){ + /* + * l: No of loops to run + */ + + double a = 1,b=Math.pow(2,-0.5),t=0.25,p=1; + for(int i=0;i