Find the real root of the equation π₯π π₯ = π πππ₯ correct to three decimal places by regula-falsi method
this equation has an infinite number of roots
#include <iostream>
#include <math.h>
using namespace std;
double f(double x)
{
return (x*pow(M_E,x)-sin(x));
}
int main()
{
double left=-3,right=-2.5;//not zero roots
double fl=f(left),fr=f(right);
double epsilon=5e-4;
double x=(left*fr-right*fl)/(fr-fl);
while(abs(f(x))>epsilon)
{
if(f(x)*fl>=0.0)
{
left=x;
fl=f(left);
}
else
{
right=x;
fr=f(right);
}
x=(left*fr-right*fl)/(fr-fl);
}
cout<<x;
return 0;
}
Answer:-2.99073
Comments
Leave a comment