Advertisement
yloplopy

Fixed Point 3.160

Apr 23rd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1.     public static void main(String[] args) {
  2.         fixedPointArrange1();
  3.     }
  4.    
  5.     private static void fixedPointArrange1() {
  6.         double x0 = 1F;
  7.         double x1 = 2F;
  8.         double x2 = 1.5;
  9.         double tol = Math.pow(10F, -6);
  10.         int loop = 50;
  11.         for(int i = 1; i <= loop; i++) {
  12.             x0 = x1;
  13.             x1 = x2;
  14.             x2 = arrange1(x1);
  15.             if(Math.abs(x1-x0) < tol && Math.abs(x2-x0) < tol && Math.abs(x2-x1) < tol) {
  16.                 System.out.println("Iteration " + i + ": " + x2);
  17.                 break;
  18.             }
  19.             System.out.println("Iteration " + i + ": " + x2);
  20.         }
  21.     }
  22.    
  23.     private static double arrange1(double x) {
  24.         //The right equation to get 1.904 which is in the bounds [1, 3]
  25.         return Math.log(3*x+1);
  26.        
  27.         //The wrong equation since it converges to 0 which is not in the bounds [1, 3]
  28.         //return ((1F-Math.pow(Math.E, x))/-3F);
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement