Advertisement
am1x

qtrap1m001.jl

Apr 10th, 2024 (edited)
1,253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.34 KB | Fixit | 0 0
  1. @fastmath function quad_trap(f, a, b, n)
  2.     h = (b - a) / n
  3.     res = 0.5 * (f(a) + f(b))
  4.     for i in 1:n-1
  5.         res += f(a + i*h)
  6.     end
  7.     res * h
  8. end
  9.  
  10.  
  11. function g()
  12.     a = 0.0
  13.     for _ in 1:100000
  14.         a = quad_trap(x -> exp(x) - 10.0, -1.0, 1.0, 10000)
  15.     end
  16.     a
  17. end
  18.  
  19. println(g())
  20. flush(stdout)
  21. @timev g()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement