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 Emulate N Dice Roller
Server-Sent Events in Spring
Java Program to Implement Lloyd’s Algorithm
HttpClient 4 – Send Custom Cookie
Overview of Spring Boot Dev Tools
Guide to Apache Commons CircularFifoQueue
How to Manually Authenticate User with Spring Security
String Operations with Java Streams
Spring Boot - Actuator
Rest Web service: Filter và Interceptor với Jersey 2.x (P1)
Giới thiệu JDBC Connection Pool
Java Program to Check Whether an Undirected Graph Contains a Eulerian Cycle
Spring Boot Actuator
New Features in Java 12
Guide to Spring 5 WebFlux
New Features in Java 10
Java Program to Find a Good Feedback Edge Set in a Graph
Default Password Encoder in Spring Security 5
Apache Tiles Integration with Spring MVC
Java Program to Implement Sorted Singly Linked List
Java Program to Implement the Alexander Bogomolny’s UnOrdered Permutation Algorithm for Elements Fro...
How to Get All Dates Between Two Dates?
A Guide to Queries in Spring Data MongoDB
New Features in Java 11
Spring Boot - Internationalization
An Introduction to Java.util.Hashtable Class
Lớp HashMap trong Java
Guava CharMatcher
Spring Data JPA @Query
New Features in Java 9
Java Program to Implement Maximum Length Chain of Pairs
Java Program to Implement Slicker Algorithm that avoids Triangulation to Find Area of a Polygon