0% found this document useful (0 votes)
213 views2 pages

Bisection Method in Netbeans

This Java program uses the bisection method to find the root of the equation f(x)=x^2+7x+12. It prompts the user to input the lower and upper bounds of the range to search. It then iteratively calculates the midpoint, evaluates the function there, and updates the bounds based on the sign of the function value. The root is found when the absolute value of the function is less than 0.00001.

Uploaded by

eiddnew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
213 views2 pages

Bisection Method in Netbeans

This Java program uses the bisection method to find the root of the equation f(x)=x^2+7x+12. It prompts the user to input the lower and upper bounds of the range to search. It then iteratively calculates the midpoint, evaluates the function there, and updates the bounds based on the sign of the function value. The root is found when the absolute value of the function is less than 0.00001.

Uploaded by

eiddnew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

/*

* To change this template, choose Tools | Templates


* and open the template in the editor.
*/

package bisectionmethodsucgang;
import java.util.Scanner;
/**
*
* @author user2
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
double xl, xu, xr, fx;
System.out.print("\n This program will determine the roots of the equation
f(x)=x^2+7x+12");
System.out.print("\n Enter the lower limit: ");
xl=input.nextDouble();
System.out.print("\n Enter the upper limit: ");
xu=input.nextDouble();

System.out.print("\n counter\t
int c;
c=1;

xl\t

xu\t

xr\t

fx\t");

do
{
xr=(xu+xl)/2;
fx= Math.pow(xr,2)+(7*xr)+12;
System.out.printf("\n

%d\t %11.4f\t %12.4f\t %13.4f\t %14.4f" , +c,+xl,+xu,+xr,

+fx);
if (fx>0)
{
xu=xr;
}
else
{
xl=xr;
}
c++;
}

while((Math.abs(fx))>=0.00001);
System.out.printf("\n The root of the equation is: %5.4f\n", +xr);
System.out.print("\n ");
System.out.print("\n ");
}

You might also like