small algorithm to approximate an integral

This commit is contained in:
opfez 2022-10-26 10:28:05 +02:00
parent f7b26cc80d
commit 21ab12cc9c
1 changed files with 7 additions and 0 deletions

7
integral-approx.hs Normal file
View File

@ -0,0 +1,7 @@
f x = x * x
n = 10000
integral f startX endX =
sum $ map (\x -> squareLen * f (x * squareLen)) [1..n]
where squareLen = (endX - startX) / n