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:
Java Program to Implement Sieve Of Eratosthenes
Java Program to Implement Uniform-Cost Search
Java Program to Implement Binary Search Tree
Java Program to Implement Extended Euclid Algorithm
How To Serialize and Deserialize Enums with Jackson
Getting Started with Stream Processing with Spring Cloud Data Flow
A Guide to the ResourceBundle
Tính trừu tượng (Abstraction) trong Java
Converting Java Date to OffsetDateTime
Java Program to Implement Solovay Strassen Primality Test Algorithm
Java Convenience Factory Methods for Collections
Spring Boot with Multiple SQL Import Files
Guide to the Fork/Join Framework in Java
Spring Boot Actuator
Comparing Strings in Java
Java Program to Perform Inorder Non-Recursive Traversal of a Given Binary Tree
Java Collections Interview Questions
Java Program to Perform Search in a BST
Registration with Spring Security – Password Encoding
So sánh HashSet, LinkedHashSet và TreeSet trong Java
Java Program to Implement the linear congruential generator for Pseudo Random Number Generation
Java Program to Perform Inorder Recursive Traversal of a Given Binary Tree
How to Iterate Over a Stream With Indices
Java Program to Generate N Number of Passwords of Length M Each
HashSet trong java
Java Program to Perform integer Partition for a Specific Case
Java Program to Implement RoleList API
A Guide to Iterator in Java
Guide To CompletableFuture
Spring Boot - Bootstrapping
Introduction to Spring Cloud Netflix – Eureka
Java Program to Implement Ternary Heap