initial commit

This commit is contained in:
Mahdi Dibaiee
2016-11-04 23:09:14 +03:30
commit 784b1b8a34
13 changed files with 360 additions and 0 deletions

21
src/Lib.hs Normal file
View File

@ -0,0 +1,21 @@
module Lib
( points
, slopeField
) where
import Numeric.MathExpr
import Data.Default.Class
type Range = (Int, Int)
points :: Range -> [(Double, Double)]
points (lower, upper) =
let range = [lower..upper]
in [ (fromIntegral x, fromIntegral y) | x <- range, y <- range ]
slopeField :: String -> [(Double, Double)] -> Double -> [((Double, Double), (Double, Double))]
slopeField math pts diff =
let d x y = evaluate def math [("x", x), ("y", y)]
half = diff / 2
res = map (\(x, y) -> ((x - half, y), (half, d x y * diff))) pts
inf = 1/0
in filter (\((x0, y0), (x, y)) -> x < inf && y < inf && x > -inf && y > -inf) res