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:
How to Manually Authenticate User with Spring Security
Reactive Flow with MongoDB, Kotlin, and Spring WebFlux
Java Program to find the number of occurrences of a given number using Binary Search approach
Java 8 Stream findFirst() vs. findAny()
Performance Difference Between save() and saveAll() in Spring Data
Java Program to Find SSSP (Single Source Shortest Path) in DAG (Directed Acyclic Graphs)
Java Program to Implement Merge Sort Algorithm on Linked List
Mảng (Array) trong Java
Giới thiệu Swagger – Công cụ document cho RESTfull APIs
Overview of the java.util.concurrent
Java Program to Implement Aho-Corasick Algorithm for String Matching
Java Program to Perform Addition Operation Using Bitwise Operators
The Basics of Java Security
Jackson – Decide What Fields Get Serialized/Deserialized
Java Program to Implement HashMap API
Convert Hex to ASCII in Java
Java Program to Implement Strassen Algorithm
Retrieve User Information in Spring Security
Java Program to Implement PrinterStateReasons API
Display Auto-Configuration Report in Spring Boot
Serve Static Resources with Spring
Handle EML file with JavaMail
Spring Boot Annotations
Java Program to Implement Efficient O(log n) Fibonacci generator
Java Program to Implement Trie
Transaction Propagation and Isolation in Spring @Transactional
Introduction to Spring Data REST
Java Program to Implement Uniform-Cost Search
Runnable vs. Callable in Java
A Guide to Java SynchronousQueue
Java Program to Check if any Graph is Possible to be Constructed for a Given Degree Sequence
Using Spring @ResponseStatus to Set HTTP Status Code