#include #include #include /*************** 表4.1の数値解とその誤差を求めるプログラム ************** ・二分法を用いて3次代数方程式の実根を求めます. *************************************************************************/ #define delta pow(10,-10) //δ(textに対応) #define epsilon 0.5*pow(10,-5) //ε(textに対応) #define a0 -3. //aの初期値 #define b0 0 //bの初期値 #define kmax 1000 //収束判定条件との比較回数の上限 double f(double x){ double y; y=pow(x,3)+6*pow(x,2)+21*x+32; return y; } /***** "区間"を引数にとり,根(必ず見つかる)を返す関数 *****/ double NIBUN(double a, double b){ int k; double c; for(k=1; k0) printf("区間が不適当です\n"); else{ root = NIBUN(a,b); printf("\n root=%8.7lf\n",root); } return 0; }