You are on page 1of 2

Newton Rhapson Bisection Method

public static void main(String[] args) { public static void main(String[] args) {
Scanner input=new Scanner(System.in); Scanner input=new Scanner(System.in);
System.out.println("Please enter the number of iterations"); System.out.println("BISECTION METHOD");
int i=input.nextInt(); System.out.println("Please input the first value");
System.out.println("Please input the first value"); double a=input.nextDouble();
double x1=input.nextDouble(); System.out.println("Please input the second value");
System.out.println(" x f(x) f'(x) x2 "); double b=input.nextDouble();
int count=1; double A;
do{ double c, fa,fc,fafc;
double fx= (x1*x1*x1)-(2*x1*x1)-(3*x1)+5; int count=1;
double fbx=(3*x1*x1*x1)-(4*x1*x1)-3; System.out.println("Please input the number of iterations");
double x2=x1-(fx/fbx); int i=input.nextInt();

System.out.printf("%8.3f %8.3f %8.3f %8.3f ", x1,fx,fbx,x2);


System.out.println(""); System.out.println(" a b c fa fc fa*fc ");
count++; do
x1=x2; {
c=(a+b)/2;
} fa=3*(a*a*a*a*a)-2*(a*a*a)+6*a-8;
while(count<=i); fc=3*(c*c*c*c*c)-2*(c*c*c)+6*c-8;

A=fc*fa;
if(A<0){
a=c;
}
else if(A>0){
b=c;

}
System.out.printf("%8.3f %8.3f %8.3f %8.3f %8.3f %8.3f",
a,b,c,fa,fc,A);
System.out.println("");
count++;

}
while(count<=i);

You might also like