You are on page 1of 2

#include<iostream>

#include<math.h>
#include<conio.h>
#include<iomanip>

using namespace std;

int main()
{
int jmlx,i,it;
int coef[10];
float x,x1,t,fx,fx1,e;

cout << "\n METODE NEWTON RAPHSON";


cout << "\nMasukkan jumlah x pada persamaan : ";
cin >> jmlx;

for(i=0;i<=jmlx;i++)
{
cout << "\n x^ "<<i<<" = ";
cin >> coef[i];
}

cout << "\n";


cout << "\nPersamaan yang dimasukkan = ";
for(i=jmlx;i>=0;i--)
{
cout << " "<<coef[1]<<"x^"<<i<<" ";
}

cout << "\n\nMasukkan Toleransi = ";


cin >> e;
cout << "\nToleransi = "<<e<<" ";

cout << "\nMasukkan nilai x1: ";


cin >> x;
cout << "\n\n----------------------------------------------\n";
cout << "\n Iterasi \t xn+1 \t f(x) \t \tf'(x) ";
cout << "\n----------------------------------------------\n";
do
{
it++;
fx=fx1=0;
for(i=jmlx;i>=1;i--)
{
fx+=coef[i] * (pow(x,i)) ;
}
fx+=coef[0];
for(i=jmlx;i>=0;i--)
{
fx1+=coef[i] * (i*pow(x,(i-1)));
}
t=x1;
x1=(x-(fx/fx1));
x=x1;
cout <<"\n\t "<<it<<" \t "<<xl<<" \t "<<fx<<" \t\t "<<fxl<<"
";
}
while((fabs(t - x))>= e);
cout << "\n Jadi, salah satu akar persamaannya = "<<xl<<"";
getch();
}

You might also like