Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Numer2_5_7 {
- public static double g(double x){
- //7//return Math.sqrt(1+1/x);
- //10.1//return (2-Math.exp(x)+x*x)/3;
- //10.2//return 0.5*(Math.sin(x)+Math.cos(x));
- }
- public static void main(String[] args) {
- double p0=0.5, tol=0.00001;
- int n0=50;
- System.out.println("0\t"+p0);
- for(int i=1; i<=n0; i++){
- double p1 = g(p0);
- double p2 = g(p1);
- if(p2-2*p1+p0 == 0) break;
- double p0h = p0-(p1-p0)*(p1-p0)/(p2-2*p1+p0);
- System.out.println(i+"\t"+p0h);
- if(Math.abs(p0h-p0) <= tol)
- break;
- p0 = p0h;
- }
- }
- }
Add Comment
Please, Sign In to add comment