Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- bisectionMethod(0, 0.2);
- System.out.println("");
- bisectionMethod(-0.2, 0);
- System.out.println("");
- bisectionMethod(8, 10);
- }
- private static void bisectionMethod(double a, double b) {
- double tol = 0.1;
- double fa = funct(a);
- int counter = 1;
- while(Math.abs(b-a) >= (tol)) {
- double m = (a+b)/2;
- double fm = funct(m);
- if((fa*fm)<=0) {
- b=m;
- }else {
- a=m;
- }
- System.out.println(counter + ": Interval = [" + a + ", " + b + "] x = " + ((a+b)/2));
- counter++;
- }
- }
- private static double funct(double x) {
- return (Math.pow(Math.E, x)-(100*Math.pow(x, 2)));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement