/* *方程:2*x*x*x - 4*x*x + 3*x - 6 = 0; */ #include <iostream> #include <cmath> using namespace std; int main(void){ double x0, x1, f0, f1; x0 = 2.5; //任意赋值 x1 = 1.5; while(fabs(x0-x1)>1e-6){ x0 = x1; f0 = 2*x0*x0*x0 - 4 *x0*x0 + 3*x0 - 6; f1 = 6*x0*x0 - 8*x0 + 3; x1 = x0 - f0/f1; } cout << x0 << endl; }