方程为 ax^3+bx^2+cx+d=0,系数由主函数给出,求x在1附近的一个实根。 牛顿迭代公式 x=x0-f(x0)/f’(x0). x0 为上一次求出的近似根。 < class="ttyprint"> float solut(float a,float b,float c,float d){ float x=1,x0,f,f1; do{ x0=x; f=((a*x0+b)*x0+c)*x0+d; f1=(3*a*x0+2*b)*x0+c; x=x0-f/f1; }while(fabs(x-x0)>=1e-3); retuen x;} >
|