コード例 #1
0
        static double Rectangle(Integrand f, int steps)
        {
            double step = (f.RightBound - f.LeftBound) / steps;
            double sum  = 0;

            for (int i = 0; i < steps; ++i)
            {
                sum += f.Function(f.LeftBound + step / 2 + i * step);
            }
            return(sum * step);
        }
コード例 #2
0
        static double Trapeze(Integrand f, int steps)
        {
            double step = (f.RightBound - f.LeftBound) / steps;
            double sum  = 0;
            double i;

            for (i = f.LeftBound; i + step <= f.RightBound; i += step)
            {
                sum += step * (f.Function(i) + f.Function(i + step)) / 2;
            }
            if (i != f.RightBound)
            {
                sum += (f.RightBound - i) * (f.Function(i) + f.Function(f.RightBound)) / 2;
            }
            return(sum);
        }