求解(计算方法实验题)
用牛顿法求一个在1.5附近的精确度为0.0005的近似根。要求:输出每一次的迭代结果和迭代次数。方程为想x^3-x^2-1=0.谁会写呀。帮忙吧,有高分。分全给你了。
2011-09-23 21:11
2011-09-23 21:12
2011-09-23 21:25
2011-09-23 21:38
2011-09-23 21:46
程序代码:#include<stdio.h>
#include<math.h>
double f(double x)
{
return x * x * x - x * x - 1;
}
double df(double x)
{
return 3 * x * x - 2 * x;
}
int main()
{
double x0, x;
int t;
x0 = 1.5;
x = x0 - f(x0) / df(x0);
t = 1;
printf("%d %f\n", t++, x);
while(fabs(x - x0) >= 0.0005)
{
x0 = x;
x = x0 - f(x0) / df(x0);
printf("%d %f\n", t++, x);
}
return 0;
}

2011-09-23 21:52
2011-09-23 22:08
2011-09-23 22:33
2011-09-24 09:26