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 Find the Minimum Element of a Rotated Sorted Array using Binary Search approach
Spring Data JPA and Null Parameters
Java Program to Implement Expression Tree
Using JWT with Spring Security OAuth
Java Program to Find the Mode in a Data Set
Java Program to Find the Median of two Sorted Arrays using Binary Search Approach
Giới thiệu thư viện Apache Commons Chain
Java Program for Topological Sorting in Graphs
Java Program to Find the Peak Element of an Array O(n) time (Naive Method)
Java Program to Implement Efficient O(log n) Fibonacci generator
Format ZonedDateTime to String
Spring Boot - Service Components
Java Program to Check whether Undirected Graph is Connected using DFS
DynamoDB in a Spring Boot Application Using Spring Data
Java Program to Implement Sieve Of Sundaram
Create a Custom Auto-Configuration with Spring Boot
Giới thiệu JDBC Connection Pool
Lớp TreeMap trong Java
Registration – Password Strength and Rules
Jackson Date
Display Auto-Configuration Report in Spring Boot
Spring Security 5 – OAuth2 Login
Java Program to implement Bit Matrix
Serverless Functions with Spring Cloud Function
Lập trình đa luồng trong Java (Java Multi-threading)
Java Program to Implement Adjacency Matrix
File Upload with Spring MVC
A Guide to BitSet in Java
Introduction to Spring Cloud CLI
Kết hợp Java Reflection và Java Annotations
Serve Static Resources with Spring
Spring REST API + OAuth2 + Angular