Advertisement
rootUser

Secant

Jun 1st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.75 KB | None | 0 0
  1. package secant;
  2.  
  3. public class Main
  4. {
  5.     public static double F(double x)
  6.     {
  7.         return ((x*x)-(4*x)-10);
  8.     }
  9.     public static void main(String[] args)
  10.     {
  11.         double x1=4,x2=2,x3=0,E=0.01;
  12.         int iteration=1;
  13.         do
  14.         {
  15.             x3 = x2-((F(x2)*(x2-x1))/(F(x2)-F(x1)));
  16.             if(Math.abs(F(x3))<E)
  17.             {
  18.                 break;
  19.             }
  20.             else
  21.             {
  22.                 x1=x2;
  23.                 x2=x3;
  24.                 System.out.println("Iteration="+iteration+" x1="+x1+" x2="+x2+" x3="+x3+" F(x1)="+F(x1)+" F(x2)="+F(x2)+" F(x3)="+F(x3));
  25.                 iteration++;
  26.             }
  27.         }
  28.         while(true);
  29.         System.out.println("The root is : "+x3);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement