用牛顿迭代法求下面方程在1.5附近的根:
// 定义函数 f(x) double f(double x) { return 2 * pow(x, 3) - 4 * pow(x, 2) + 3 * x - 6; } // 定义导数 f'(x) double f_prime(double x) { return 6 * pow(x, 2) - 8 * x + 3; } int main() { double x = 1.5; // 初始猜测值 double x_next; int iter = 0; // 迭代计数器 while (iter < MAX_ITER) { x_next = x - f(x) / f_prime(x); // 迭代公式 if (fabs(x_next - x) < EPS) { // 误差满足条件 break; } x = x_next; iter++; } printf("方程的根: %.5lf\n", x_next); printf("迭代次数: %d\n", iter); return 0; }
。
死去的数值分析回来了
#include &l...
用户登录可进行刷题及查看答案
#include <stdio.h> #include <math.h> int main() { double x1, x0, f, f1; x1 = 1.5; do { x0 = x1; f = ((2 * x0 - 4) * x0 + 3) * x0 - 6; f1 = (6 * x0 - 8) * x0 + 3; x1 = x0 - f / f1; } while (fabs(x1 - x0) >= 1e-5); printf("方程在1.5附近的根为:%lf\n", x1); return 0; }
登录后提交答案