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:
Loại bỏ các phần tử trùng trong một ArrayList như thế nào trong Java 8?
Java Program to Represent Graph Using Adjacency List
Java Program to Check if it is a Sparse Matrix
Java Program to Represent Graph Using Adjacency Matrix
Hướng dẫn sử dụng Printing Service trong Java
Java Program to Perform Uniform Binary Search
Java Program to Implement Radix Sort
Spring Boot - Internationalization
Java Program to Find Number of Spanning Trees in a Complete Bipartite Graph
Overview of Spring Boot Dev Tools
Java Program to Implement Graham Scan Algorithm to Find the Convex Hull
Spring Boot - Bootstrapping
Creating a Custom Starter with Spring Boot
Apache Commons Collections SetUtils
Inheritance with Jackson
Hướng dẫn Java Design Pattern – Decorator
Merging Two Maps with Java 8
Concurrent Test Execution in Spring 5
Java Program to Perform Searching Using Self-Organizing Lists
Creating a Generic Array in Java
Guide to System.gc()
JPA/Hibernate Persistence Context
Spring 5 and Servlet 4 – The PushBuilder
Java Program to Implement AA Tree
Lớp TreeMap trong Java
Từ khóa static và final trong java
Test a REST API with Java
Explain about URL and HTTPS protocol
Simplify the DAO with Spring and Java Generics
Java Program to Implement Skew Heap
The Thread.join() Method in Java
Compare Two JSON Objects with Jackson