Ejemplo n.º 1
0
        public static double Integrate(Func <double, double> func,
                                       double a, double b, double alpha, double beta, int n)
        {
            var Mu = Mathematics.GetMuArray(n, a, b, alpha, beta);

            double[] X = new double[n];
            double   h = (b - a) / (n - 1);

            for (int i = 0; i < n; i++)
            {
                X[i] = a + h * i;
            }
            double[,] matrix = new double[n, n];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    matrix[i, j] = Math.Pow(X[j], i);
                }
            }
            var A = Mathematics.GausMethod(matrix, Mu);

            double integralSum = 0;

            for (int i = 0; i < n; i++)
            {
                integralSum += func(X[i]) * A[i];
            }
            return(integralSum);
        }
Ejemplo n.º 2
0
        public static double GetOptStepRichardson(Func <Func <double, double>,
                                                        double, double, double, double, int, int, double> method, Func <double, double> func,
                                                  double a, double b, double alpha, double beta, int n, int r, int ada, double epsilon)
        {
            double startStep = (b - a);

            double[,] A = new double[r + 1, r + 1];
            double[] B = new double[r + 1];
            double[] X = new double[r + 1];
            do
            {
                for (int i = 0; i < A.GetLength(0); i++)
                {
                    double step = startStep / Math.Pow(2, i);
                    for (int j = 0; j < A.GetLength(0); j++)
                    {
                        if (j == 0)
                        {
                            A[i, j] = -1;
                        }
                        else
                        {
                            A[i, j] = Math.Pow(step, ada + j - 1);
                        }
                    }
                    B[i] = -method(func, a, b, alpha, beta, n, Mathematics.GetGoodNum(a, b, step));
                }
                X          = Mathematics.GausMethod(A, B);
                startStep /= 2;
            } while (Math.Abs(X[0] + B[r]) > epsilon);

            return(startStep / Math.Pow(2, r - 1));
        }
Ejemplo n.º 3
0
        public static double Integrate(Func <double, double> func,
                                       double a, double b, double alpha, double beta, int n)
        {
            var Mu    = Mathematics.GetMuArray(2 * n, a, b, alpha, beta);
            var SLAE  = new double[n, n];
            var bSLAE = new double[n];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    SLAE[i, j] = Mu[j + i];
                }
                bSLAE[i] = -Mu[n + i];
            }
            var acoefs   = Mathematics.GausMethod(SLAE, bSLAE);
            var polcoefs = new double[acoefs.Length + 1];

            for (int i = 0; i < polcoefs.Length - 1; i++)
            {
                polcoefs[i] = acoefs[i];
            }
            polcoefs[polcoefs.Length - 1] = 1;

            var nodes = GetSquarePolynomialRoots(polcoefs);

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    SLAE[i, j] = Math.Pow(nodes[j], i);
                }
                bSLAE[i] = Mu[i];
            }
            var    intcoefs = Mathematics.GausMethod(SLAE, bSLAE);
            double result   = 0;

            for (int i = 0; i < n; i++)
            {
                result += intcoefs[i] * func(nodes[i]);
            }
            return(result);
        }