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:
Hướng dẫn Java Design Pattern – Interpreter
Receive email using POP3
Java Program to Find Maximum Element in an Array using Binary Search
The DAO with Spring and Hibernate
Wiring in Spring: @Autowired, @Resource and @Inject
Jackson Annotation Examples
Introduction to Using FreeMarker in Spring MVC
Java Program to Find Nearest Neighbor Using Linear Search
Transactions with Spring and JPA
Concatenating Strings In Java
Spring Boot - Exception Handling
Spring Boot - Tomcat Deployment
Request a Delivery / Read Receipt in Javamail
Tips for dealing with HTTP-related problems
Cachable Static Assets with Spring MVC
Beans and Dependency Injection
Debug a HttpURLConnection problem
How to Round a Number to N Decimal Places in Java
Spring MVC and the @ModelAttribute Annotation
Java Program to Check if a Given Binary Tree is an AVL Tree or Not
Java Program to Check Whether an Undirected Graph Contains a Eulerian Path
Giới thiệu java.io.tmpdir
Spring Autowiring of Generic Types
Guide To CompletableFuture
How to Read a File in Java
Removing Elements from Java Collections
OAuth2 for a Spring REST API – Handle the Refresh Token in AngularJS
Java Program to Implement RenderingHints API
Java Program to Implement wheel Sieve to Generate Prime Numbers Between Given Range
Java Program to Find SSSP (Single Source Shortest Path) in DAG (Directed Acyclic Graphs)
Hướng dẫn Java Design Pattern – Composite
Java Program to Check Whether Graph is DAG