Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void bisectionMethod(double a, double b) {
- double tol = 0.0000001;
- List<Double> pastValues = new ArrayList<Double>();
- double fa = funct(a);
- int counter = 1;
- while(Math.abs(b-a) >= (tol)) {
- double m = (a+b)/2;
- pastValues.add(m);
- double fm = funct(m);
- if((fa*fm)<=0) {
- b=m;
- }else {
- a=m;
- }
- if(pastValues.size() < 4) {
- System.out.println(counter + ": Interval = [" + a + ", " + b + "] x = " + m);
- }else {
- double y0 = Math.log(Math.abs(pastValues.get(pastValues.size()-1) - pastValues.get(pastValues.size()-2)));
- double x0 = Math.log(Math.abs(pastValues.get(pastValues.size()-2) - pastValues.get(pastValues.size()-3)));
- double y1 = x0;
- double x1 = Math.log(Math.abs(pastValues.get(pastValues.size()-3) - pastValues.get(pastValues.size()-4)));
- double roc = (y1-y0)/(x1-x0);
- System.out.println(counter + ": Interval = [" + a + ", " + b + "] x = " + m);
- System.out.println("Rate of Convergence = " + roc);
- }
- counter++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement