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:
Introduction to the Java NIO2 File API
A Guide to TreeMap in Java
Vector trong Java
Hướng dẫn Java Design Pattern – Memento
Java Program to Show the Duality Transformation of Line and Point
Java – Write an InputStream to a File
Lớp LinkedHashMap trong Java
Spring Cloud AWS – Messaging Support
A Quick Guide to Spring MVC Matrix Variables
Java InputStream to String
Server-Sent Events in Spring
Using the Map.Entry Java Class
Spring Cloud AWS – EC2
Intersection of Two Lists in Java
Java Program to Print only Odd Numbered Levels of a Tree
New Features in Java 9
Tạo ứng dụng Java RESTful Client không sử dụng 3rd party libraries
A Guide to WatchService in Java NIO2
Java Convenience Factory Methods for Collections
Spring Data MongoDB – Indexes, Annotations and Converters
Find the Registered Spring Security Filters
Most commonly used String methods in Java
Quick Guide to @RestClientTest in Spring Boot
Java Program to Implement the RSA Algorithm
Java Program to Implement Merge Sort on n Numbers Without tail-recursion
Check if a String is a Palindrome in Java
Write/Read cookies using HTTP and Read a file from the internet
Java Program to Implement Skip List
Java Stream Filter with Lambda Expression
Java Program to Implement Quick Sort with Given Complexity Constraint
Hướng dẫn sử dụng Java Reflection
Java Program to Generate All Possible Combinations Out of a, b, c, d, e