#include <stdio.h> #include <math.h> int main() { float left,right,mid; float fleft, fright,fmid; left=-10.; right=10.; mid=(left+right)/2; fmid=2*mid*mid*mid-4*mid*mid+3*mid-6; // 2x3-4x2+3x-6 while(fabs(fmid)>1e-6) { fleft=2*left*left*left-4*left*left+3*left-6; fright=2*right*right*right-4*right*right+3*right-6; if(fleft*fmid>0) left=mid; else right=mid; mid=(left+right)/2; fmid=2*mid*mid*mid-4*mid*mid+3*mid-6; } printf("the solution of the equation is %.2f.\n",mid); return 1; }
用二分法求方程2x3-4x2+3x-6=0在(-10,10)之间的根
最新推荐文章于 2020-12-17 16:57:21 发布