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 ConcurrentHashMap API
Cachable Static Assets with Spring MVC
Java Program to Find Minimum Number of Edges to Cut to make the Graph Disconnected
Lớp lồng nhau trong java (Java inner class)
A Guide to EnumMap
Java Program to Implement Interpolation Search Algorithm
Batch Processing with Spring Cloud Data Flow
Java Program to find the number of occurrences of a given number using Binary Search approach
Java Program to find the maximum subarray sum using Binary Search approach
Java Program to Check the Connectivity of Graph Using DFS
Java Program to Use Dynamic Programming to Solve Approximate String Matching
Receive email by java client
The Java 8 Stream API Tutorial
Guide to @JsonFormat in Jackson
Java Program to Implement Euclid GCD Algorithm
Java Program to Implement Hopcroft Algorithm
Spring REST API + OAuth2 + Angular
Java Program to Find Second Smallest of n Elements with Given Complexity Constraint
Java String Conversions
Sử dụng CyclicBarrier trong Java
Introduction to Thread Pools in Java
Custom HTTP Header with the HttpClient
An Intro to Spring Cloud Vault
Java Program to Perform Finite State Automaton based Search
Java Program to Check if a Given Binary Tree is an AVL Tree or Not
Spring Data JPA @Modifying Annotation
Java Program to Find the Median of two Sorted Arrays using Binary Search Approach
Java Program to Implement a Binary Search Tree using Linked Lists
DynamoDB in a Spring Boot Application Using Spring Data
Java Program to Implement Quick Sort with Given Complexity Constraint
Java Program to find the maximum subarray sum O(n^2) time(naive method)
Hướng dẫn sử dụng Java Reflection