Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @fastmath function quad_trap(f, a, b, n)
- h = (b - a) / n
- res = 0.5 * (f(a) + f(b))
- for i in 1:n-1
- res += f(a + i*h)
- end
- res * h
- end
- function g()
- a = 0.0
- for _ in 1:100000
- a = quad_trap(x -> exp(x) - 10.0, -1.0, 1.0, 10000)
- end
- a
- end
- println(g())
- flush(stdout)
- @timev g()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement