public static double Simpsons(double a, double b, int m, int l, int k)
 {
     int m2 = m;
     double[] x = new double[m + 1];
     double h = (b - a) / m;
     for (int i = 0; i <= m; ++i)
     {
         x[i] = a + i * h;
     }
     double jh = 0.0;
     for (int i = 0; i < m; ++i)
     {
         MU f1 = new MU(x[i], k);
         MU f2 = new MU(x[i] + h/2, k);
         MU f3 = new MU(x[i + 1], k);
         jh = jh + h / 6 * (f1.reVal() + 4 * f2.reVal() + f3.reVal());
     }
     m *= l;
     x = new double[m + 1];
     h = (b - a) / m;
     for (int i = 0; i <= m; ++i)
     {
         x[i] = a + i * h;
     }
     double jh2 = 0.0;
     for (int i = 0; i < m; ++i)
     {
         MU f1 = new MU(x[i], k);
         MU f2 = new MU(x[i] + h / 2, k);
         MU f3 = new MU(x[i + 1], k);
         jh2 = jh2 + h / 6 * (f1.reVal() + 4 * f2.reVal() + f3.reVal());
     }
     Integral j = new Integral(b, a);
     double rm=(jh2-jh)/(double)(Math.Pow(l,4) - 1);
     return (jh2 + rm);
 }
 public static void KFormula(double a, double b, int n)
 {
     double[] mu = new double[2*n];
     for (int i = 0; i < 2*n; ++i)
         mu[i] = IntegralMu(a, b, i);
     Console.WriteLine();
     Console.WriteLine("Weight:");
     for (int i = 0; i < 2 * n; ++i)
         Console.Write("Mu{0}\t",i);
     Console.WriteLine();
     for (int i = 0; i < 2*n; ++i)
         Console.Write("{0:f5} ", mu[i]);
     Console.WriteLine();
     int l;
     Matrix m = new Matrix(n,n+1);
     for (int i = 0; i < n; ++i)
     {
         l = i;
         for (int j = n; j >=0; --j)
         {
             m[i, j] = mu[l];
             ++l;
         }
     }
     m.SwapStolb(0, n);
     Console.WriteLine();
     Console.WriteLine("Matrix of the system to find the odds w(x):");
     for (int i = 0; i < m.GetLength(0); ++i)
         m[i, n] = -1 * m[i, n];
     for (int i = 0; i <m.GetLength(0); ++i)
     {
         for (int j = 0; j < m.GetLength(1); ++j)
             Console.Write("{0:f3} ",m[i, j]);
         Console.WriteLine();
     }
     Console.WriteLine();
     double[] c;
     c = MethodKramera(m);
     MethodBessekcii(a, b, c, n);
     double[] node = new double[nodes.Count];
     for (int i = 0; i < node.Length; ++i)
         node[i] = nodes.Dequeue();
     Console.WriteLine("The roots of the polynomial w (x) (future nodes):");
     for (int i = 0; i < node.Length; ++i)
         Console.WriteLine("X{0} = {1:f15}", i, node[i]);
     if (node.Length != n)
     {
         Console.WriteLine("Error! Bisection method has found roots < n");
         return;
     }
     m = new Matrix(n, n + 1);
     for (int i = 0; i < m.GetLength(0); ++i)
         for (int j = 0; j < m.GetLength(1); ++j)
             if (j < n) m[i, j] = Math.Pow(node[j], i); else m[i, j] = mu[i];
     Console.WriteLine();
     Console.WriteLine("Matrix of the system to find the odds quadrature formula:");
     for (int i = 0; i < m.GetLength(0); ++i)
     {
         for (int j = 0; j < m.GetLength(1); ++j)
             Console.Write("{0:f3} ", m[i, j]);
         Console.WriteLine();
     }
     Console.WriteLine();
     c = MethodKramera(m);
     Console.WriteLine("Coefficient of the quadrature formula:");
     for (int i = 0; i < c.Length; ++i)
         Console.WriteLine("A{0} = {1:f15} ",i+1, c[i]);
     Console.WriteLine();
     Fun f = new Fun(node);
     double result=0.0;
     Integral I=new Integral(b,a);
     for (int i = 0; i < n; ++i)
         result += f.reVal(i) * c[i];
     Console.WriteLine("Checking:");
     for (int i = 0; i < 2 * n; ++i)
     {
         double s=0;
         for (int j = 0; j < n; ++j)
             s+=c[j]*Math.Pow(node[j],i);
         Console.WriteLine("Mu{0} = {1:f5} = {2:f5}", i, mu[i], s);
     }
     Console.WriteLine();
     Console.WriteLine("Result:");
     Console.WriteLine("J(h) = {0:f15}", result);
     Console.WriteLine("J = {0:f15}", I.reVal());
     Console.WriteLine("R = {0:f15}", Math.Abs(I.reVal() - result));
 }