squiggle/packages/squiggle-lang/examples/integrate.squiggle

14 lines
358 B
Plaintext
Raw Normal View History

2022-09-15 11:17:19 +00:00
integrate(fun, min, max) = {
// assume that min and max are integers.
epsilon = 1
l = max - min
meanF(t) = fun(t)
intervals = map(List.upTo(0, (l/epsilon)), ({|n| min + n*epsilon}))
values = map(intervals, ({ |x | meanF(x)}))
result = reduce(values, 0, ({|acc, x| acc + x})) * epsilon
result
}
f(x) = x
integrate(f, 1, 100k)