• API
• FAQ
• Tools
• Archive
SHARE
TWEET Bisection Method Problem yloplopy  Apr 22nd, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. public static void main(String[] args) {
2.         bisectionMethod();
3.     }
4.
5.     private static void bisectionMethod() {
6.         double a = 0;
7.         double b = 1;
8.         double tol = 0.000001;
9.
10.         double fa = funct(a);
11.         int counter = 1;
12.         while(Math.abs(b-a) >= (tol)) {
13.             System.out.println(counter + ": Interval = [" + a + ", " + b + "] x = " + ((a+b)/2));
14.             double m = (a+b)/2;
15.             double fm = funct(m);
16.             if((fa*fm)<=0) {
17.                 b=m;
18.             }else {
19.                 a=m;
20.             }
21.             counter++;
22.         }
23.         System.out.println(counter + ": Interval = [" + a + ", " + b + "] x = " + ((a+b)/2));
24.     }
25.     private static double funct(double x) {
26.         return ((3*Math.pow(x, 3))-(5*Math.pow(x, 2))-(4*x)+4);
27.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top