Pencarian akar dengan metode Bisection (Source code C++)


untuk ide menggunakan Codeblock –> codeblocks.org

</pre>
#include
 #include
 #include
 #include
 #include
 using namespace std;
 double xl,xu,e,xr,temp;
 int counter;
 double fx (double x)
 {
 return exp(-x)-x;
 }
 int main()
 {

cout<<"masukkan nilai Xl ="<>xl;
 cout<<"masukkan nilai Xu ="<>xu;
 cout<<"masukkan nilai error % ="<>e;
 double h =(xu-xl)/e;

if ((fx(xl)*fx(xu))<0)
 {
 while( true)
 {
 xr=(xl+xu)/2;

cout<<counter<<" XL= "<<xl<< " XU= "<<xl<<" XR= "<<xr<< " Prosentase = "<<(abs((xr-temp)/xr)*100)<<"%"<=e)
 {

if ((fx(xl)*fx(xr))<0)
 {
 temp=xr;
 xu=xr;

}
 else
 {
 temp=xr;
 xl=xr;
 }
 }
 else
 {
 break;
 }
 counter++;

}
 cout<<" akar= "<<xr<<endl;
 }
 else
 {
 cout<<endl<<"tidak ada akar.."<<endl;
 }
 }
<pre>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s