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:
Guide to Java Instrumentation
Java Program to Implement Queue
Configure a Spring Boot Web Application
Logout in an OAuth Secured Application
Java Program to Optimize Wire Length in Electrical Circuit
Java Program to Implement Extended Euclid Algorithm
Spring Boot - Batch Service
Simple Single Sign-On with Spring Security OAuth2
Java Program to Implement CountMinSketch
Wrapper Classes in Java
Java Program to Check Whether an Input Binary Tree is the Sub Tree of the Binary Tree
What is Thread-Safety and How to Achieve it?
How to Get the Last Element of a Stream in Java?
Converting String to Stream of chars
Java Program to Implement Gaussian Elimination Algorithm
Java Program to Print the Kind of Rotation the AVL Tree is Undergoing
Java Program to Implement SynchronosQueue API
Spring Security Form Login
Spring Boot - Google OAuth2 Sign-In
A Guide To UDP In Java
Các kiểu dữ liệu trong java
Recommended Package Structure of a Spring Boot Project
Partition a List in Java
Java Program to Implement the linear congruential generator for Pseudo Random Number Generation
Java Program to Generate All Subsets of a Given Set in the Lexico Graphic Order
Java Program to Perform Finite State Automaton based Search
Jackson – Bidirectional Relationships
Java Program to Implement Stack using Linked List
Java Program to Solve any Linear Equations
Java Program for Douglas-Peucker Algorithm Implementation
Spring Security Remember Me
LinkedHashSet trong java