rootUser

Newton Rapshon

Jun 1st, 2016
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.76 KB | None | 0 0
  1. package newton.raphson;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main
  6. {
  7.     static double F(double x)
  8.     {
  9.         double result = (x)* (x) + 3 * (x) + 2 ;
  10.         return result;
  11.     }
  12.     static double dF(double x)
  13.     {
  14.         double result = 2 * (x) + 3;
  15.         return result;
  16.     }
  17.     public static void main(String[] args)
  18.     {
  19.         Scanner scanner = new Scanner(System.in);
  20.         System.out.print("Enter the value of x0 : ");
  21.         double x0=scanner.nextDouble();
  22.         double iteration = 1;
  23.         double E = 0.001;
  24.         do
  25.         {
  26.             x0 = x0 - (F(x0)/dF(x0)) ;
  27.             System.out.println("Iteration : "+iteration+" x0 = "+x0);
  28.             iteration++;
  29.         }while(Math.abs(F(x0))>=E);
  30.     }
  31.    
  32. }
Add Comment
Please, Sign In to add comment