豹子头误入白堂虎污:麻烦用c语言帮忙编写下列程序!!!

来源:百度文库 编辑:高考问答 时间:2024/04/30 15:05:49
用牛顿迭代法解方程2x的三次方-4x的平方+3x-6=0 在x=1.5附近的是实根,精度要求10的负5次方

/* 迭代法求方程的解*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define h 1.E-10
/*定义迭代方程(即压缩映射)*/
double f(double x0)
{
x0=pow((2*x0+5),1.0/3);/*计算方法书155页上的例6.1*/
return x0;
}
/*求绝对值*/
double sub(double x)
{if(x>=0)return x;
else return -x;
}
main()
{double x0=2.5,x,s=0.0;
do{
x=f(x0);
s=sub(x-x0);
x0=x;
}while(s>h);
printf("x=%.10lf\n",x);
getch();
}

牛顿迭代法
很典型的算法,很多书上都有程序啊