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); }
public static Complex IntegrateComplex(FunctionComplexOneVar f, double low, double high, int steps) { return IntegrateSimpsonsRule(f, low, high, steps); //return IntegrateTrapezoidRule(f, low, high, steps); }
public static Complex IntegrateComplex(FunctionComplexOneVar f, double low, double high, int steps) { return(IntegrateSimpsonsRule(f, low, high, steps)); //return IntegrateTrapezoidRule(f, low, high, steps); }
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; }