Skip to content

Instantly share code, notes, and snippets.

@yikuansun
Created December 23, 2022 16:06
Show Gist options
  • Save yikuansun/7fb6c0eaa4c1fa1b826f73e9810ad12a to your computer and use it in GitHub Desktop.
Save yikuansun/7fb6c0eaa4c1fa1b826f73e9810ad12a to your computer and use it in GitHub Desktop.
Evaluate definite integrals in JavaScript
Math.integrate = function(fn, a, b, deltaX = 0.0001) {
var out = 0;
for (var x = a; x < b; x += deltaX) out += deltaX * fn(x);
return out;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment