Artemis.Engine.Maths.Integrator.Simpsons C# (CSharp) Метод

Simpsons() публичный статический Метод

Integrate the given function f between the given limits a and b using Simpson's method with n steps.
public static Simpsons ( double>.Func f, double a, double b, int n ) : double
f double>.Func
a double
b double
n int
Результат double
        public static double Simpsons(Func<double, double> f, double a, double b, int n)
        {
            if (n % 2 != 0)
                throw new ArgumentException(
                    String.Format(
                        "For Simpson's method to be used, the number of steps must be even. " +
                        "The number of steps received was {0}.", n
                        )
                    );
            if (a == b)
            {
                return 0;
            }
            double s = (b - a) / n, alpha = s / 3.0, interval = s, m = 4.0;
            double sum = f(a) + f(b);

            for (int i = 0; i < n - 1; i++)
            {
                sum += m * f(a + interval);
                m = 6 - m;
                interval += s;
            }
            return alpha * sum;
        }
Integrator