Exemplo n.º 1
0
        //Default grid with 1, 2 end 4 steps
        private int CalcOptStepCqf(double start, double end, double accuracy, TypeOfCqf typeOfCqf)
        {
            var defaultIntegralsValue = new[] { CalcIntegralCqf(start, end, 1, typeOfCqf), CalcIntegralCqf(start, end, 2, typeOfCqf), CalcIntegralCqf(start, end, 4, typeOfCqf) };
            var aitkinConstant        = CalcAitkinConstant(defaultIntegralsValue, new [] { 1, 2, 4 });
            var defaultStepsRelation  = 2;
            var optimalStepSize       = 1.0 / 2 * Math.Pow(accuracy * (1 - Math.Pow(defaultStepsRelation, -aitkinConstant)) / Math.Abs(defaultIntegralsValue[2] - defaultIntegralsValue[1]), (double)1 / aitkinConstant);

            return((int)(1.0 / optimalStepSize));
        }
Exemplo n.º 2
0
        private double CalcIntegralCqf(double start, double end, int parts, TypeOfCqf typeOfCqf)
        {
            var integralValue = 0.0;

            var sizeOfStep = (end - start) / parts;

            for (var i = 0; i < parts; i++)
            {
                double[] nodes;
                switch (typeOfCqf)
                {
                case TypeOfCqf.Iqf:
                    nodes = new double[3];

                    nodes[0] = start + sizeOfStep * i;
                    nodes[1] = start + sizeOfStep * (i + 1.0 / 2);
                    nodes[2] = start + sizeOfStep * (i + 1);

                    integralValue += _iqfHelper.CalcIntegral(nodes[0], nodes[2], nodes);
                    break;

                case TypeOfCqf.Gqf:
                    nodes = new double[2];

                    nodes[0] = start + sizeOfStep * i;
                    nodes[1] = start + sizeOfStep * (i + 1);

                    integralValue += _gqfHelper.CalcIntegral(nodes[0], nodes[1]);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(typeOfCqf), typeOfCqf, null);
                }
            }
            return(integralValue);
        }
Exemplo n.º 3
0
        public double CalcIntegralWithAccuracy(double start, double end, double accuracy, TypeOfCqf typeOfCqf)
        {
            var steps          = CalcOptStepCqf(start, end, accuracy, typeOfCqf);
            var arrayWithSteps = new[] { steps };
            var integralValues = new[] { CalcIntegralCqf(start, end, steps, typeOfCqf) };

            var currentAccuracy = Double.MaxValue;

            while (currentAccuracy > accuracy)
            {
                steps *= 2;

                var newIntegralValue = CalcIntegralCqf(start, end, steps, typeOfCqf);

                integralValues = AddValueToArray(integralValues, newIntegralValue);

                arrayWithSteps = AddValueToArray(arrayWithSteps, steps);

                currentAccuracy = CalcAccuracyRichardson(integralValues, arrayWithSteps, start, end);
            }

            return(integralValues.Last());
        }