#include<iostream>
#include<cmath>
using namespace std;
double f_origianal(double a, double b, double c, double d, double newx)
{
return a * pow(newx, 3) + pow(newx, 2) * b + c * newx + d;
}
double f_after_or(double a, double b, double c, double d, double newx)
{
return 3.0 * a * pow(newx, 2) + b * 2 * newx + c;
}
double f(double a, double b, double c, double d, double newx)
{
//cout << f_origianal(a, b, c, d, newx) / f_after_or(a, b, c, d, newx) << endl;
if (abs(f_origianal(a, b, c, d, newx) / f_after_or(a, b, c, d, newx)) <= 1e-5)
return newx;
newx = newx - f_origianal(a, b, c, d, newx) / f_after_or(a, b, c, d, newx);
return f(a, b, c, d, newx);
}
int main()
{
double a, b, c, d;
cin >> a >> b >> c >> d;
cout << f(a, b, c, d, 1.0);
return 0;
}
标签:return,递归,double,after,算法,newx,pow,迭代法,origianal From: https://www.cnblogs.com/atrue/p/17340170.html