Guest User

Untitled

a guest
May 26th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. public class Numer2_5_7 {
  2.  
  3.     public static double g(double x){
  4.         //7//return Math.sqrt(1+1/x);
  5.         //10.1//return (2-Math.exp(x)+x*x)/3;
  6.         //10.2//return 0.5*(Math.sin(x)+Math.cos(x));
  7.     }
  8.  
  9.     public static void main(String[] args) {
  10.         double p0=0.5, tol=0.00001;
  11.         int n0=50;
  12.         System.out.println("0\t"+p0);
  13.         for(int i=1; i<=n0; i++){
  14.             double p1 = g(p0);
  15.             double p2 = g(p1);
  16.             if(p2-2*p1+p0 == 0) break;
  17.  
  18.             double p0h = p0-(p1-p0)*(p1-p0)/(p2-2*p1+p0);
  19.             System.out.println(i+"\t"+p0h);
  20.             if(Math.abs(p0h-p0) <= tol)
  21.                 break;
  22.             p0 = p0h;
  23.         }
  24.  
  25.     }
  26.  
  27. }
Add Comment
Please, Sign In to add comment