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


untuk ide menggunakan Codeblock –> codeblocks.org


#include
 #include
 #include
 #include
 #include

using namespace std;
 int main()
 {
 double a;
 couta;
 double b;
 coutb;
 double n;
 coutn;
 double fa=exp(-a)-a;
 double fb=exp(-b)-b;
 double fab=fa*fb;
 double h =(b-a)/n;
 double fx;
 cout<<"nilai f(a) = "<<fa<<endl;;
 cout<<"nilai f(b) = "<<fb<<endl;
 cout<<"nilai f(a)x f(b) = "<<fab<<endl;
 cout<<"nilai h = "<<h<<endl<<endl;
 double x=a;

if (fab<0)
 {
 cout<<endl<<"akar di temukan"<<endl;
 double temp,temp_1;
 cout << "X | f(X) "<<endl;
 for (double i=0; i<=n; i++)
 {

fx=exp(-x)-x;
 cout<<i<<" | "<<x<<" | "<<fx<=0)
 {
 temp=x;
 temp_1=x+h;
 }
 x+=h;
 }

double m_fxk = abs(exp(-temp)-temp);
 double m_fxk_1=abs(exp(-temp_1)-temp_1);
 cout<<endl<<"nilai mutlak fxk= "<<m_fxk<<endl;
 cout<<"nilai mutlak fxk= "<<m_fxk_1<<endl;
 if (m_fxk<m_fxk_1==false)
 {
 cout<<"nilai x= "<<temp_1<<endl;
 }
 else
 {
 cout<<"nilai x= "<<temp<<endl;
 }
 }
 else
 {
 cout<<endl<<"akar tidak ditemukan"<<endl;
 }

return 0;
 }

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