Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package secant;
- public class Main
- {
- public static double F(double x)
- {
- return ((x*x)-(4*x)-10);
- }
- public static void main(String[] args)
- {
- double x1=4,x2=2,x3=0,E=0.01;
- int iteration=1;
- do
- {
- x3 = x2-((F(x2)*(x2-x1))/(F(x2)-F(x1)));
- if(Math.abs(F(x3))<E)
- {
- break;
- }
- else
- {
- x1=x2;
- x2=x3;
- System.out.println("Iteration="+iteration+" x1="+x1+" x2="+x2+" x3="+x3+" F(x1)="+F(x1)+" F(x2)="+F(x2)+" F(x3)="+F(x3));
- iteration++;
- }
- }
- while(true);
- System.out.println("The root is : "+x3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement