This is a Java Program to Implement Regular Falsi Algorithm. Regular Falsi method is used for finding roots of functions.
Here is the source code of the Java Program to Implement Regular Falsi Algorithm. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | /** * Java Program to Implement Regular Falsi Algorithm **/ public class RegularFalsi { /** function to find root for **/ public double f( double x) { /** make your own function here but accordingly change (s, t) **/ return Math.cos(x) - x * x * x; // return x * x * x - 3 * x + 4; // return Math.cos(x) - 3 * x + 1; // return 2 * x - Math.log(x)/Math.log(10) - 7; // return x * x - Math.log(x) - 12; } /** function to find root **/ public double findRoot( double s, double t, double e, int m) { double r = 0.0 ,fr; int n, side = 0 ; /** starting values at endpoints of interval **/ double fs = f(s); double ft = f(t); for (n = 0 ; n < m; n++) { r = (fs * t - ft * s) / (fs - ft); if (Math.abs(t - s) < e * Math.abs(t + s)) break ; fr = f(r); if (fr * ft > 0 ) { /** fr and ft have same sign, copy r to t **/ t = r; ft = fr; if (side == - 1 ) fs /= 2 ; side = - 1 ; } else if (fs * fr > 0 ) { /** fr and fs have same sign, copy r to s **/ s = r; fs = fr; if (side == + 1 ) ft /= 2 ; side = + 1 ; } else { /** fr * f_ very small (looks like zero) **/ break ; } } return r; } /** Main function **/ public static void main(String[] args) { System.out.println( "Regular Falsi Test " ); RegularFalsi rf = new RegularFalsi(); /** lower limit **/ double s = 0 ; /** upper limit **/ double t = 1 ; /** half of upper bound for relative error **/ double e = 5E- 15 ; /** number of iterations **/ int iterations = 100 ; System.out.println( "\nRoot : " + rf.findRoot(s, t, e, iterations)); } } |
Output:
1 2 3 | Regular Falsi Test Root : 0.8654740331016145 |
Related posts:
Java Program to Implement the Checksum Method for Small String Messages and Detect
Quick Guide to java.lang.System
New Features in Java 14
Receive email using POP3
Hướng dẫn sử dụng biểu thức chính quy (Regular Expression) trong Java
Java Optional as Return Type
Implementing a Binary Tree in Java
Spring Security Authentication Provider
Java Program to Implement HashTable API
A Guide to the Java ExecutorService
Java Byte Array to InputStream
Java Program to Implement Max Heap
Creating a Custom Starter with Spring Boot
Java Program to Implement TreeMap API
Introduction to Spring MVC HandlerInterceptor
Custom Thread Pools In Java 8 Parallel Streams
Spring Boot Security Auto-Configuration
Hướng dẫn Java Design Pattern – Interpreter
HttpClient 4 – Follow Redirects for POST
Java Program to Generate All Pairs of Subsets Whose Union Make the Set
Spring Boot - Securing Web Applications
Hướng dẫn sử dụng luồng vào ra nhị phân trong Java
Spring Boot - Batch Service
Java Program to Implement Sorted Doubly Linked List
Java Program to Solve the Fractional Knapsack Problem
Java Switch Statement
Quick Guide to Spring MVC with Velocity
Spring Boot with Multiple SQL Import Files
Spring Cloud AWS – RDS
Java Program to Find Median of Elements where Elements are Stored in 2 Different Arrays
Spring WebClient and OAuth2 Support
Java 8 StringJoiner