Integrate() public static method

Computes the area under the integral for the given function, in the given integration interval, using the Trapezoidal rule.
public static Integrate ( double>.Func func, double a, double b, int steps ) : double
func double>.Func The unidimensional function whose integral should be computed.
a double The beginning of the integration interval.
b double The ending of the integration interval.
steps int The number of steps into which the integration interval will be divided.
return double
示例#1
0
        /// <summary>
        ///   Computes the area of the function under the selected <see cref="Range"/>.
        ///   The computed value will be available at this object's <see cref="Area"/>.
        /// </summary>
        ///
        /// <returns>
        ///   True if the integration method succeeds, false otherwise.
        /// </returns>
        ///
        public bool Compute()
        {
            for (int i = 0; i < s.Length; i++)
            {
                s[i] = 1;
            }

            double sum = 0;
            double a   = range.Min;
            double b   = range.Max;

            for (int k = 0; k < s.Length; k++)
            {
                sum  = s[0];
                s[0] = TrapezoidalRule.Integrate(Function, a, b, 1 << k);

                for (int i = 1; i <= k; i++)
                {
                    int p = (int)Math.Pow(4, i);
                    s[k] = (p * s[i - 1] - sum) / (p - 1);

                    sum  = s[i];
                    s[i] = s[k];
                }
            }

            Area = s[s.Length - 1];

            return(true);
        }