module Numeric.Probability.Example.Predator where
import Numeric.Probability.Visualize (
Vis, Color(Green, Red),
figP, figure, title,
showParams, xLabel, yLabel, plotL, color, label,
)
g, d, s, e :: Float
g = 1.02
d = 0.98
s = 0.01
e = 0.01
v0 :: Float
v0 = 1
p0 :: Float
p0 = 1
dv :: (Float,Float) -> Float
dv (v,p) = (g*v - s*v*p) `max` 0
dp :: (Float,Float) -> Float
dp (v,p) = (d*p + e*v*p) `max` 0
dvp :: (Float, Float) -> (Float, Float)
dvp vp' = (dv vp', dp vp')
vp :: [(Float, Float)]
vp = (v0,p0):map dvp vp
vs :: [Float]
vs = map fst vp
ps :: [Float]
ps = map snd vp
fig1 :: Int -> Vis
fig1 n = figP figure{title="Predator/Prey Simulation "++
showParams [g,d,s,e] ["g","d","s","e"],
xLabel="Time (generation)",
yLabel="Population"}
[(plotL (take n vs)){color=Green,label="Victim"},
(plotL (take n ps)){color=Red,label="Prey"}]