-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeometric.R
56 lines (50 loc) · 1.23 KB
/
geometric.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
print("Loading function geometricPlot")
geometricPlot = function(
n0=1, lam=1, startTime=0, timeSteps=10, logscale=FALSE,
xlab="time (years)", ylab="I should label my axes!", plotType="b"
){
forward <- 0:timeSteps
t <- startTime + forward
n <- n0*lam^forward
log = ifelse(logscale, "y", "")
par(cex=1.6)
plot(t, n,
xlab=xlab, ylab=ylab, type=plotType, log=log
)
}
print("Loading function exponentialPlot")
exponentialPlot = function(
n0=1, r=1, startTime=0, runTime=10, timeSteps=100,
logscale=FALSE, xlab="time (days)", ylab="Bacteria"
){
elapsedTime <- runTime*(0:timeSteps)/timeSteps
t <- startTime + elapsedTime
n <- n0*exp(r*elapsedTime)
log = ifelse(logscale, "y", "")
par(cex=1.6)
plot(t, n,
xlab=xlab, ylab=ylab, type="l", log=log
)
}
stochGen <- function(n0=1, lam=1, startTime=0, timeSteps=10, logscale=FALSE
, xlab="time (years)", ylab="Label your axes!", plotType="b"
, numSims=0
){
forward <- 0:timeSteps
t <- startTime + forward
n <- n0*lam^forward
log = ifelse(logscale, "y", "")
par(cex=1.6)
plot(t, n,
xlab=xlab, ylab=ylab, type=plotType, log=log
)
if (numSims>0){
for (sim in 1:numSims){
n <- n0
for (c in 1:timeSteps){
n[c+1] <- rpois(1, lam*n[c])
}
lines(t, n, col="blue")
}
}
}