next up previous
Next: 簡単な説明 Up: 2分法による方程式の数値解法 Previous: 2分法のアルゴリズム

例: 代数方程式の近似解

ここでは, 一例として代数方程式 $x^5+x-1=0$ の実数解の近似値を求めて見ます. 簡単にわかるように, この方程式は区間 $[0, 1]$ に唯一の実数解を持ちます. 一般の 5 次方程式に関しては, Abel, Galoisにより代数的な解の公式が作れない 事が証明されています.(代数学 I で勉強して下さい.)

/* File name 7-2.c   */
#include <stdio.h>
#include <math.h>

#define EPSILON 1.0E-10

double fun(double x);

main()
{
      double a=0.0; /* The initial value. */
      double b=1.0;
      double c=(a+b)/2.0;

      while (fabs((a-b)/c)>EPSILON){
            if (fun(c) == 0.0) break; /* c is the root */
            else if (fun(a)*fun(c) > 0.0 ){ /* The root is between b and c. */
                  a=c;
            }
            else { /* The root is between a and c.  */
                  b=c;
            }
            c= (a+b)/2.0;
      }
      printf("The root is about %1.10f\n.", c);
}

double fun(double x)
{
      return x*x*x*x*x+x-1;
}



Next: 簡単な説明 Up: 2分法による方程式の数値解法 Previous: 2分法のアルゴリズム