Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pkgfalse.position;
- import java.util.Scanner;
- public class Main
- {
- static double F(double x)
- {
- double result = (x)*(x)*(x) + (x)*(x) + (x) + 7 ;
- return result;
- }
- public static void main(String[] args)
- {
- int i = 1;
- double x1,x2,x0;
- double f2,f0,f1,t;
- double ESP = 0.001;
- Scanner s = new Scanner(System.in);
- System.out.println("\nEnter the value of x1: ");
- x1 = s.nextDouble(); //-2
- System.out.println("\nEnter the value of x2: ");
- x2 = s.nextDouble(); //-3
- System.out.println("\n__________________________________________________________________\n");
- System.out.println("\niteration\t x1\t x2\t x0\t f1\t f2\t f0");
- System.out.println("\n___________________________________________________________________\n");
- do
- {
- x0=x1 - ((F(x1)*(x2-x1))/(F(x2)-F(x1)));
- f1=F(x1);
- f2=F(x2);
- f0=F(x0);
- System.out.println("\n"+" "+i+" "+x1+" "+x2+" "+x0+" "+f1+" "+f2+" "+f0);
- if(f1*f0<0)
- {
- x2=x0;
- }
- else
- {
- x1=x0;
- }
- i++;
- }
- while(Math.abs(f0)>=ESP);
- System.out.println("\n__________________________________________________________\n");
- System.out.println("\n\nApp.root = "+x0);
- }
- }
Add Comment
Please, Sign In to add comment