Accord.Math.Integration.RombergMethod.Compute C# (CSharp) Method

Compute() public method

Computes the area of the function under the selected Range. The computed value will be available at this object's Area.
public Compute ( ) : bool
return bool
        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;
        }

Usage Example

Example #1
0
        /// <summary>
        ///   Computes the area under the integral for the given function,
        ///   in the given integration interval, using Romberg's method.
        /// </summary>
        ///
        /// <param name="steps">The number of steps used in Romberg's method. Default is 6.</param>
        /// <param name="func">The unidimensional function whose integral should be computed.</param>
        /// <param name="a">The beginning of the integration interval.</param>
        /// <param name="b">The ending of the integration interval.</param>
        ///
        /// <returns>The integral's value in the current interval.</returns>
        ///
        public static double Integrate(Func <double, double> func, double a, double b, int steps)
        {
            var romberg = new RombergMethod(steps, func, a, b);

            romberg.Compute();

            return(romberg.Area);
        }
All Usage Examples Of Accord.Math.Integration.RombergMethod::Compute