11.
x3 + 2x2 + 10x – 20 = 0
Metode
komputasi numerik
#include<iostream>
#include<math.h>
using
namespace std;
double
fungsi(double x){
return pow(x,3) + 2*pow(x,2) + 10*x - 20;
}
int
main(){
double a, b;
cin >> a >> b;
double T;
double error;
bool apakahSalah = 0;
do{
T=(b+a)/2;
if(fungsi(a)*fungsi(b)<0){
if(fungsi(a)*fungsi(T)<0) b=T;
else if(fungsi(b)*fungsi(T)<0)
a=T;
double tmperror = (b-a);
if(tmperror<0) error = tmperror
* (-1);
else error = tmperror;
}
else{
cout << "Silahkan coba
angka lain!\n";
apakahSalah = 1;
break;
}
}
while(error > 0.000001);
if(apakahSalah!=1){
cout << "a\t= " <<
a << endl;
cout << "b\t= "
<< b << endl;
cout << "error\t= "
<< error << endl;
}
return 0;
}
EmoticonEmoticon