Java program for Regula Falsi Method

Java program for regula falsi method. This page provides program for regula falsi method in java programming language. To understand regula falsi method with definition, formula, example, graph, theory, advantages and disadvantages, application read Regula Falsi Method.

Example: Regula Falsi Method in Java

import java.io.*; 
  
class GFG
{ 
  
    static int MAX_ITER = 1000000; 

    static double func(double x) 
    { 
        return (x * x * x - x * x + 2); 
    } 
  
    static void regula_falsi(double number1, double number2) 
    { 
        if (func(number1) * func(number2) >= 0)  
        { 
            System.out.println("You have not assumed right number1 and number2"); 
        } 

        double root = number1;  
  
        for (int i = 0; i < MAX_ITER; i++)  
        { 
           c = (a * func(number1) - number2 * func(number1))  
                 / (func(number1) - func(number1)); 
  
 
            if (func(root) == 0) 
                break; 
  

            else if (func(root) * func(number1) < 0) 
                number2 = root; 
            else
                number1 = root; 
        } 
        System.out.println("The value of root is : " + (int)root); 
    } 
  

    public static void main(String[] args) 
    { 
        double number1 = -200, number2 = 300; 
        regula_falsi(number1, number2); 
    } 
}

Output:



Comments