You are on page 1of 2

HALF INTERVAL METHOD

package halfinterval;

import java.util.Scanner;

/**

* @author ???

*/

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 X1, X2, Xr, fx1, fx2, fxr, fx;

double tol = 0.00001;

System.out.print("Enter the value of X1: ");

X1 = input.nextDouble();

System.out.print("Enter the value of X2: ");

X2 = input.nextDouble();

System.out.println("\tc\t\tX1\t\tX2\t\tXr\t\tfx1\t\tfx2");

fx1 = (3*(Math.pow(X1, 5)))-(2*(Math.pow(X1,3)))+(6*X1)-8;

fx2 = (3*(Math.pow(X2, 5)))-(2*(Math.pow(X2,3)))+(6*X2)-8;

if(fx1<0 && fx2>0 || fx1>0 && fx2<0)

double c=1;
do

Xr = (X1+X2)/2;

fxr = (3*(Math.pow(Xr, 5)))-(2*(Math.pow(Xr,3)))+(6*Xr)-8;

fx = fxr*fx1;

System.out.printf("\n%11.4f\t%11.4f\t%11.4f\t%11.4f\t%11.4f\t%11.4f\t", c, X1, X2, Xr, fxr,fx1);

if(fx>0)

X1=Xr;

You might also like