Stucture used to return values with associated error tolerances
コード例 #1
0
ファイル: Polynomial.cs プロジェクト: valhentai/SharpVectors
        /// <summary>
        /// Romberg - adapted from "Numerical Recipes in C"
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        public double Romberg(double min, double max)
        {
            int    MAX       = 20;
            double TOLERANCE = 1e-7;
            int    K         = 4;

            double[]       s      = new double[MAX + 1];
            double[]       h      = new double[MAX + 1];
            ValueWithError result = new ValueWithError(0, 0);

            h[0] = 1.0;
            for (int j = 1; j <= MAX; j++)
            {
                s[j - 1] = Trapezoid(min, max, j);
                if (j >= K)
                {
                    result = Polynomial.Interpolate(h, s, K, j - K, 0.0);
                    if (Math.Abs(result.Error) < TOLERANCE * result.Value)
                    {
                        break;
                    }
                }
                s[j] = s[j - 1];
                h[j] = 0.25 * h[j - 1];
            }

            return(result.Value);
        }
コード例 #2
0
ファイル: Polynomial.cs プロジェクト: codebutler/savagesvg
        /// <summary>
        /// Romberg - adapted from "Numerical Recipes in C"
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        public double Romberg(double min, double max)
        {
            int MAX = 20;
            double TOLERANCE = 1e-7;
            int K = 4;
            double[] s = new double[MAX+1];
            double[] h = new double[MAX+1];
            ValueWithError result = new ValueWithError(0,0);

            h[0] = 1.0;
            for ( int j = 1; j <= MAX; j++ )
            {
                s[j-1] = trapezoid(min, max, j);
                if ( j >= K )
                {
                    result = Polynomial.Interpolate(h, s, K, j-K, 0.0);
                    if ( Math.Abs(result.Error) < TOLERANCE*result.Value ) break;
                }
                s[j] = s[j-1];
                h[j] = 0.25 * h[j-1];
            }

            return result.Value;
        }