I want to find approximate polynomial roots of a polynomial equation.
#include <fstream>
#include <cmath>
#include <iostream>
using namespace std;
bool polynomial_algorithm(double a, double b, double c, double d, double e,int& sum, int i1, int i2)
{
double y = 0;
for (double i = i1; i <= i2; i += 0.0000001)
{
double x = (a * pow(i, 4) + b * pow(i, 3) + c * pow(i, 2) + d * i + e);
}
return true;
}
int main()
{
int i1,i2,sum=0;
double a, b, c, d, e;
//interval configuration:
i1 = -1;
i2 = 2;
cout << "interval (" << i1 << ";" << i2 << ")" << endl;
//configuration of values:
a = -1;
b = 3;
c = static_cast<double>(-4) / 9;
d = static_cast<double>(-4) / 3;
e = static_cast<double>(32) / 81;
cout << a << " " << b << " " << c << " " << d << " " << e << endl;
if (i2 < i1)
{
cout << "invalid interval";
}
cout << endl << "compiling" << endl;
cout << endl << "compilation success: "<<polynomial_algorithm(a,b,c,d,e,sum,i1,i2) << endl;
}
This is the code I currently have, how do I got about checking if double x ≈ 0 in bool polynomial_algorithm?
I tried reading articles about the std::abs function and other stuff but it just really fried my brain, I appreciate the help if I get any.
I figured it out by using a
boolvariable to determine when a polynomial hits0watching when it becomes negative or positive by reading from a file.