コード例 #1
0
 public DFun(double y)
 {
     this.d0 = y;
     Fun f = new Fun(y);
     this.d1 = f.ReVal();
     this.d2 = -2 * y * this.d1;
     this.d3 = -2 * Math.Pow(this.d1,2) - 2 * y * this.d2;
     this.d4 = -2 * (this.d0 * this.d3 + 3 * this.d1 * this.d2);
     this.d5 = -2 * (this.d0 * this.d4 + 3 * Math.Pow(this.d2, 2) + 4 * this.d3 * this.d1);
     this.d6 = -2 * (this.d0 * this.d5 + 5 * this.d4 * this.d1 + 10 * this.d3 * this.d2);
 }
コード例 #2
0
 public static void Adams(double x0, double y0, double h, int n)
 {
     double[,] d = new double[2 * n, 2 * n];
     for (int i = 0; i <= 4; ++i)
     {
         d[i, 0] = xx[i];
         d[i, 1] = yy[i];
         Fun f = new Fun(yy[i]);
         d[i, 2] = h * f.ReVal();
     }
     int m = 3;
     for (int j = 3; j <= 6; ++j)
     {
         for (int i = 0; i <= m; ++i)
             d[i, j] = d[i + 1, j - 1] - d[i, j - 1];
         --m;
     }
     for (int i = 5; i <= n + 5; ++i)
     {
         d[i, 0] = d[i - 1, 0] + h;
         double yk = d[i - 1, 1] + d[i - 1, 2] + (d[i - 2, 3] / 2) + (5 * d[i - 3, 4] / 12) + (3 * d[i - 4, 5] / 8) + (251 * d[i - 5, 6] / 720);
         d[i, 1] = yk;
         Fun f = new Fun(yk);
         d[i, 2] = h * f.ReVal();
         int j = 3;
         for (int l = i - 1; l >= 0; --l)
         {
             d[l, j] = d[l + 1, j - 1] - d[l, j - 1];
             ++j;
             if (j > 7) break;
         }
     }
     Console.WriteLine("X\t   Y\t     q\t       D1\t D2\t   D3\t     D4\t");
     for (int i = 0; i <= n + 2; ++i)
     {
         for (int j = 0; j <= 6; ++j)
             if (d[i, j] < 0) Console.Write("{0:f6} ", d[i, j]); else Console.Write(" {0:f6} ", d[i, j]);
         Console.WriteLine();
     }
     Console.WriteLine("Rn = {0:f6}", Math.Abs(r[n] - d[n + 2, 1]));
 }
コード例 #3
0
 public static void Runge(double x0, double y0, double h, int n)
 {
     double[] x = new double[2 * n];
     double[] y = new double[2 * n];
     x[0] = x0; y[0] = y0;
     Console.WriteLine("X        Y");
     Console.WriteLine("{0:f6} {1:f6}", x0, y0);
     for (int i = 1; i <= n; ++i)
     {
         Fun f = new Fun(y[i - 1]);
         double k1 = h * f.ReVal();
         f = new Fun(y[i - 1] + k1 / 2);
         double k2 = h * f.ReVal();
         f = new Fun(y[i - 1] + k2 / 2);
         double k3 = h * f.ReVal();
         f = new Fun(y[i - 1] + k3);
         double k4 = h * f.ReVal();
         x[i] = x[i - 1] + h;
         y[i] = y[i - 1] + (k1 + 2 * k2 + 2 * k3 + k4) / 6;
         Console.WriteLine("{0:f6} {1:f6}", x[i], y[i]);
     }
     Console.WriteLine("Rn = {0:f15}", Math.Abs(r[n] - y[n]));
 }
コード例 #4
0
 public static void Ailer3(double x0, double y0, double h, int n)
 {
     double[] x = new double[2 * n];
     double[] y = new double[2 * n];
     x[0] = x0; y[0] = y0;
     for (int i = 1; i <= n; ++i)
     {
         x[i] = x[i - 1] + h;
         Fun f1 = new Fun(y[i - 1]);
         Fun f = new Fun(y[i - 1] + h * f1.ReVal());
         y[i] = y[i - 1] + h/2 * (f1.ReVal() + f.ReVal());
     }
     DFun g = new DFun(y0);
     Console.WriteLine(" X        Y        R");
     for (int i = 0; i <= n; ++i)
     {
         double ri = Math.Abs(r[i] - y[i]);
         if (x[i] < 0) Console.Write("{0:f6}", x[i]); else Console.Write(" {0:f6}", x[i]);
         if (y[i] < 0) Console.Write("{0:f6} ", y[i]); else Console.Write(" {0:f6} ", y[i]);
         Console.WriteLine("{0:f8}", ri);
     }
 }