Skip to content

Instantly share code, notes, and snippets.

@lamrongol
Created April 25, 2014 18:44
Show Gist options
  • Save lamrongol/11299217 to your computer and use it in GitHub Desktop.
Save lamrongol/11299217 to your computer and use it in GitHub Desktop.
/**
* @see <a href="http://en.wikipedia.org/wiki/Riemann_sum#Middle_sum">http://en.wikipedia.org/wiki/Riemann_sum#Middle_sum</a>
*/
public static double riemannSum(Function<Double, Double> func, double beginPoint, double endPoint, double interval){
double result = 0;
//Middle Sum(Maybe error sum is most minimal)
for(double x = beginPoint; x<=endPoint; x+=interval){
result += func.apply(x+interval/2);
}
result *= interval;
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment