This is a Java Program to Implement Cubic convergence 1/pi Algorithm. Cubic convergence is an algorithm used to calculate the value of 1/p.
Here is the source code of the Java Program to Implement Cubic convergence 1/pi Algorithm. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
/** ** Java Program to Implement Cubic convergence 1/pi Algorithm **/ import java.util.Scanner; /** Class CubicConvergencePi **/ public class CubicConvergencePi { /** compute 1/pi **/ public double getOneByPi(int k) { double ak = 1.0/3.0; double sk = (Math.sqrt(3) - 1)/2; double ak1, sk1, rk1; for (int i = 0; i < k; i++) { rk1 = 3.0 / (1 + 2 * Math.pow((1 - sk * sk * sk), (1.0/3.0))); sk1 = (rk1 - 1)/2.0; ak1 = rk1 * rk1 * ak - Math.pow(3, i) * (rk1 * rk1 - 1); ak = ak1; sk = sk1; } return ak; } /** Main function **/ public static void main (String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Cubic Convergence 1/Pi Algorithm Test\n"); /** Make an object of CubicConvergence class **/ CubicConvergencePi cc = new CubicConvergencePi (); System.out.println("Enter number of iterations"); int k = scan.nextInt(); System.out.println("\nValue of 1/pi : "+ cc.getOneByPi(k)); } }
Output:
Cubic Convergence 1/Pi Algorithm Test Enter number of iterations 3 Value of 1/pi : 0.3183098861837896
Related posts:
A Guide to JUnit 5 Extensions
Spring Cloud AWS – Messaging Support
Java Program to subtract two large numbers using Linked Lists
Guide to DelayQueue
Spring Cloud AWS – EC2
Biến trong java
Apache Commons Collections BidiMap
Spring Data JPA @Modifying Annotation
List Interface trong Java
Java Program to Search for an Element in a Binary Search Tree
Prevent Brute Force Authentication Attempts with Spring Security
Hướng dẫn Java Design Pattern – Interpreter
Giới thiệu luồng vào ra (I/O) trong Java
Java Program to Find Nearest Neighbor for Dynamic Data Set
Java Program to Use Above Below Primitive to Test Whether Two Lines Intersect
Java Program to Implement Hash Tables Chaining with List Heads
Quick Guide to Spring Bean Scopes
Using Optional with Jackson
Java Program to Represent Graph Using 2D Arrays
Debug a JavaMail Program
Java Program to Implement Bubble Sort
Jackson vs Gson
Java Stream Filter with Lambda Expression
Java Program to Check Cycle in a Graph using Topological Sort
Java Program to Perform Searching in a 2-Dimension K-D Tree
Summing Numbers with Java Streams
Spring WebFlux Filters
Java Program to Check if a Directed Graph is a Tree or Not Using DFS
Guide to BufferedReader
Java Program to Find Transitive Closure of a Graph
Spring Boot - Bootstrapping
Java Program to Implement RenderingHints API