예제 #1
0
        public static T Integrate(IFunction <T> function, IVector <T> from, IVector <T> to, int order)
        {
            if (from.Count != to.Count)
            {
                throw new ArgumentOutOfRangeException();
            }

            var point = GaussLegendrePointFactory.GetGaussPoint(from[0], to[0], order);
            var sum   = LinearAlgebra.Value.GetZeroValue();

            for (var i = 0; i < point.Abscissas.Length; i++)
            {
                LinearAlgebra.Value.Add(ref sum, IntegrateInternal(function, new Vector <T>(new[] { point.Abscissas[i] }), point.Weights[i], 0, from, to, order));
            }

            return(sum);
        }
예제 #2
0
        private static T IntegrateInternal(IFunction <T> function, IVector <T> currentParameters, T currentWeight, int currentIndex, IVector <T> from, IVector <T> to, int order)
        {
            if (currentIndex == from.Count - 1)
            {
                return(LinearAlgebra.Value.Mult(function.Value(currentParameters), currentWeight));
            }

            currentIndex++;
            var point = GaussLegendrePointFactory.GetGaussPoint(from[currentIndex], to[currentIndex], order);

            var sum = LinearAlgebra.Value.GetZeroValue();

            for (var i = 0; i < point.Abscissas.Length; i++)
            {
                LinearAlgebra.Value.Add(ref sum, IntegrateInternal(function, new Vector <T>(currentParameters.Union(new[] { point.Abscissas[i] })), LinearAlgebra.Value.Mult(point.Weights[i], currentWeight), currentIndex, from, to, order));
            }

            return(sum);
        }