Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

help with do while loop code

$
0
0
 do {
          y1=f(x1);
          y2=f(x2);
          x3=x2-(y2*(x2-x1))/(y2-y1);
          x1=x2;
          x2=x3;
          
          
          cout<<"x3 is: "<<x3<<endl;
          a=a+1;
       }
       while (a<=3);
      
      cout<<"the secant root is: "<<x3<<endl;



In this code its supposed to do the secant root findint method where x3 takes on new values 4 times and supposed to output the last value. However, this is the output i am getting.


x3 is: 3.48195
x3 is: 3.48155
x3 is: 3.48155
x3 is: 3.48155
the secant root is: 3.48155

how come the x3 is being the same?

sorry about the code.

do {
y1=f(x1);
y2=f(x2);
x3=x2-(y2*(x2-x1))/(y2-y1);
x1=x2;
x2=x3;


cout<<"x3 is: "<<x3<<endl;
a=a+1;
}
while (a<=3);

cout<<"the secant root is: "<<x3<<endl;

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>