#include <iostream>
#include <cmath>
using namespace std;
double f(double x) {
return 2 * pow(x, 3) - 4 * pow(x, 2) + 3 * x - 6;
}
double f_p(double x) {
return 6 * pow(x, 2) - 8 * x + 3;
}
int main()
{
double x = 1.5;
double t = 1e-6;
while(fabs(f(x)) > t)
{
x = x - f(x)/f_p(x); //牛顿迭代公式
}
cout << "方程的解为: " << x;
return 0;
}
}
用牛顿迭代法求方程2x3-4x2+3x-6=0在1.5附近的根。
于 2024-03-16 23:32:14 首次发布