我为多项式函数(ax^6 + bx^5 + cx^4 + dx^3 + ex^3 + fx^2 + gx + h)编写了一个 cpp 代码(我假设所有变量都是 1 ,所以我刚刚定义了a)并且我想将它转换为8085模拟器,你能帮我吗?这是我的代码:
#include <iostream>
#define EPSILON 0.001
using namespace std;
double func(double x)
{
int a=1;
return a*x*x*x*x*x*x+a*x*x*x*x*x+a*x*x*x*x+a*x*x*x+a*x*x*x+a*x*x+a*x+a;
}
double derivFunc(double x)
{
int a=1;
return 6*a*x*x*x*x*x+5*a*x*x*x*x+4*a*x*x*x+3*a*x*x+3*a*x*x+2*a*x+a;
}
void newtonRaphson(double x)
{
double h = func(x) / derivFunc(x);
while (abs(h) >= EPSILON)
{
h = func(x)/derivFunc(x);
x = x - h;
}
cout << "The value of the root is : " << x;
}
int main()
{
double x0 = 10;
newtonRaphson(x0);
return 0;
}