Safety threshold for faecal coliform count in water for contact recreational sports:
\[ \begin{align*} \frac{dC}{dt} & = \frac{F}{V}c_{in} - \frac{F}{V}C(t) , \,\, C(0)= c_0 \\ \\ C(t) & = c_{in} - (c_{in} - c_0) e^{-Ft/V } \end{align*} \]
\[ \begin{align*} C(t) & = c_{in} - (c_{in} - c_0) e^{-Ft/V } \\ & = c_0 e^{-Ft/V } \end{align*} \]
Solve for \( t \), using \( C = C_L \):
\[ t = - \frac{V}{F} \ln \left( \frac{C_L}{c_0} \right) \]
Formula \[ t = - \frac{V}{F} \ln \left( \frac{C_L}{c_0} \right) \]
V <- 28*10^6
F <- 4*10^6
CL <- 4*10^6
c0 <- 10^7
t <- - V/F*log(CL/c0)
t
[1] 6.414035
\[ C(t) = c_{in} - (c_{in} - c_0) e^{-Ft/V } \]
\[ \frac{dC}{dt} = \frac{F}{V} \left[ c_{in} - C(t) \right] , \,\, C(0)= c_0 \]
\[ \lim_{t \rightarrow \infty} C(t) = \lim_{t \rightarrow \infty} \left( c_{in} - (c_{in} - c_0) e^{-Ft/V }\right) = c_{in} \]
\[ \begin{align*} c_{in} & = 3 \times 10^6 \mathrm{bacteria}/ \mathrm{m}^3 \\ F & = (4*12) \times 10^6 \mathrm{m}^3/ \mathrm{year} \end{align*} \]
rk4plot <- function (f, x0 , y0 , h, n) {
x <- rep(0, n)
y <- rep(0, n)
x[1] <- x0
y[1] <- y0
for(i in 1:n) {
s1 <- h*f(x[i], y[i])
s2 <- h*f(x[i] + h/2, y[i] + s1/2)
s3 <- h*f(x[i] + h/2, y[i] + s2/2)
s4 <- h*f(x[i] + h, y[i] + s3)
y[i+1] <- y[i] + s1/6 + s2/3 + s3/3 + s4/6
x[i+1] <- x[i] + h
}
return(plot(x,y,type="l", col="blue"))
}
f <- function(x, C) { 48/28*(3 - C) }
rk4plot(f, 0, 10, 0.1, 40)
rk4data <- function (f, x0 , y0 , h, n) {
x <- rep(0, n)
y <- rep(0, n)
x[1] <- x0
y[1] <- y0
for(i in 1:n) {
s1 <- h*f(x[i], y[i])
s2 <- h*f(x[i] + h/2, y[i] + s1/2)
s3 <- h*f(x[i] + h/2, y[i] + s2/2)
s4 <- h*f(x[i] + h, y[i] + s3)
y[i+1] <- y[i] + s1/6 + s2/3 + s3/3 + s4/6
x[i+1] <- x[i] + h
}
return(data.frame (x = x, C = y))
}
f <- function(x, C) { 48/28*(3 - C) }
rk4data(f, 0, 10, 0.2, 10)
x C
1 0.0 10.000000
2 0.2 7.968438
3 0.4 6.526483
4 0.6 5.503016
5 0.8 4.776583
6 1.0 4.260978
7 1.2 3.895013
8 1.4 3.635260
9 1.6 3.450893
10 1.8 3.320033
11 2.0 3.227152
F1 <- function(x) {(10 + 6*sin(2*pi*x))}
c1 <- function(x) {(10 + 10*cos(2*pi*x))}
f <- function(x, C) { F1(x)/28*(c1(x) - C) }
rk4plot(f, 0, 6, 0.1, 80)
F1 <- function(x) {(10 + 6*sin(2*pi*x))}
c1 <- function(x) {(10 + 10*cos(2*pi*x))}
f <- function(x, C) { F1(x)/28*(c1(x) - C) }
rk4data(f, 0, 6, 0.1, 10)
x C
1 0.0 6.000000
2 0.1 6.550003
3 0.2 7.020280
4 0.3 7.183187
5 0.4 7.032754
6 0.5 6.770244
7 0.6 6.592136
8 0.7 6.545226
9 0.8 6.595532
10 0.9 6.768673
11 1.0 7.132961