#include <iostream> #include <cmath> using namespace std; double f(double x) { return 5 * pow(x, 3) - 3 * pow(x, 2) + 2 * x - 8; } double fx(double x) { return 15 * pow(x, 2) - 6 * x + 2; } double newton(double x0, int t) { double x = x0; double e = pow(10, -t); while (fabs(f(x)) > e) { x = x - f(x) / fx(x); } return x; } int main() { int n; cin >> n; double x0 = 1.1; double r = newton(x0, n); cout.precision(n + 3); cout << r << endl; return 0; }

#include <iostream> #include <cmath> using namespace std; double f(double x) { return 5 * pow(x, 3) - 3 * pow(x, 2) + 2 * x - 8; } double fx(double x) { return 15 * pow(x, 2) - 6 * x + 2; } double newton(double x0, int t) { double x = x0; double e = pow(10, -t); while (fabs(f(x)) > e) { x = x - f(x) / fx(x); } return x; } int main() { int n; cin >> n; double x0 = 1.1; double r = newton(x0, n); cout.precision(n + 3); cout << r << endl; return 0; }
用户634390339
2023年11月02日
|
浏览 192

[]

我要提问
复制内容
分享给好友
AI编程问答网 免责声明:
以上内容除特别注明外均来源于网友提问,AI编程问答网回答,权益归原著者所有;