Skip to content

Instantly share code, notes, and snippets.

@jniac
Last active November 30, 2018 23:16
Show Gist options
  • Save jniac/7228690ef95a835f01bf8f155b3298f6 to your computer and use it in GitHub Desktop.
Save jniac/7228690ef95a835f01bf8f155b3298f6 to your computer and use it in GitHub Desktop.
integrate = (f, { min = 0, max = 1, n = 1000 } = {}) => {
let s = 0
for (let i = 0; i < n; i++) {
let x = min + (max - min) * (i + 1/2) / n
s += f(x)
}
return s * (max - min) / n
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment