示例#1
0
        private static Complex IntegrateSimpsonsRule(FunctionComplexOneVar f, double low, double high, int steps)
        {
            Complex retval   = 0;
            double  stepSize = (high - low) / (double)steps;
            Complex leftVal  = 0;
            Complex midVal   = 0;
            Complex rightVal = 0;

            leftVal = f(low);

            if (steps % 2 == 1)
            {
                steps++;
            }

            for (int i = 2; i <= steps; i += 2)
            {
                double xmid   = low + (i - 1) * stepSize;
                double xright = low + i * stepSize;

                midVal   = f(xmid);
                rightVal = f(xright);

                retval += (leftVal + 4 * midVal + rightVal) * stepSize / 3.0;

                leftVal = rightVal;
            }

            return(retval);
        }
示例#2
0
 public static Complex IntegrateComplex(FunctionComplexOneVar f, double low, double high, int steps)
 {
     return IntegrateSimpsonsRule(f, low, high, steps);
     //return IntegrateTrapezoidRule(f, low, high, steps);
 }
示例#3
0
 public static Complex IntegrateComplex(FunctionComplexOneVar f, double low, double high, int steps)
 {
     return(IntegrateSimpsonsRule(f, low, high, steps));
     //return IntegrateTrapezoidRule(f, low, high, steps);
 }
示例#4
0
        private static Complex IntegrateSimpsonsRule(FunctionComplexOneVar f, double low, double high, int steps)
        {
            Complex retval = 0;
            double stepSize = (high - low) / (double)steps;
            Complex leftVal = 0;
            Complex midVal = 0;
            Complex rightVal = 0;

            leftVal = f(low);

            if (steps % 2 == 1)
                steps++;

            for (int i = 2; i <= steps; i += 2)
            {
                double xmid = low + (i - 1) * stepSize;
                double xright = low + i * stepSize;

                midVal = f(xmid);
                rightVal = f(xright);

                retval += (leftVal + 4 * midVal + rightVal) * stepSize / 3.0;

                leftVal = rightVal;

            }

            return retval;
        }