values 0.1, 1 and 10. Check exercise 5.1b
on how this was done. Make 4 informative plots (also check exercise 5.1b
for this): (1) with time (on the x-axis) vs. CO
. Make sure that all plots have 3
lines, one for each of the three
values (0.1, 1 and 10).
Added parts to function RatesCUVET1 as already defined
above in exercise 5.1a):
# Compute the time coefficient
TC <- (W + K * Volume ) / (Area * Vm)
# Gather auxiliary information
AUX <- c(C = C, P = P, TC = TC)
Full function definition with these lines added:
# Define the function returning the rates of change of the state variables with respect to time
RatesCUVET1 <- function(t, y, parms){
with(as.list(c(y, parms)),{
# Compute auxiliary/helper functions
# Concentration of CO2 inside the chamber
C <- W / Volume
# Net rate of photosynthesis (no respiration assumed)
P <- Vm * C / (K + C)
# Compute rate equations
# Net rate of change of amount of CO2 in chamber
dWdt <- - P * Area
# Gather all rates of change in a vector
# - the rates should be in the same order as the states (as specified in 'y')
# - it can be a named vector, but does not need to be
RATES <- c(dWdt = dWdt)
# Optional: get in/out flow used to compute mass balances (or set MB <- NULL)
# not included here (thus here use MB <- NULL), see template 3
MB <- NULL
# Compute the time coefficient
TC <- (W + K * Volume ) / (Area * Vm)
# Optional: gather auxiliary variables that should be returned (or set AUX <- NULL)
# - this should be a named vector or list!
AUX <- c(C = C, P = P, TC = TC)
# Return result as a list
# - the first element is a vector with the rates of change (in the same order as 'y')
# - all other elements are (optional) extra output, which should be named
outList <- list(c(RATES, MB), # the rates of change
AUX) # additional output per time step
return(outList)
})
}
We can plot the TC after solving the model in the same way we did in
exercise 5.1b):
Volume <- 0.0001 # m3
Cini <- 10.0 # initial CO2 concentration in g CO2 m-3
states_ode45_K1 <- ode(
y = InitCUVET1(W = Volume * Cini),
times = seq(0, 2000, by = 1),
func = RatesCUVET1,
parms = ParmsCUVET1(K = 1,
Volume = Volume,
Cini = Cini), # all others at their default values
method = "ode45")
states_ode45_K10 <- ode(
y = InitCUVET1(W = Volume * Cini),
times = seq(0, 2000, by = 1),
func = RatesCUVET1,
parms = ParmsCUVET1(K = 10,
Volume = Volume,
Cini = Cini), # all others at their default values
method = "ode45")
states_ode45_K.1 <- ode(
y = InitCUVET1(W = Volume * Cini),
times = seq(0, 2000, by = 1),
func = RatesCUVET1,
parms = ParmsCUVET1(K = 0.1,
Volume = Volume,
Cini = Cini), # all others at their default values
method = "ode45")
Now we can plot it:
par(mfrow = c(2, 2), mar = c(4, 4, 1, 1)) # with mar=c(bottom, left, top, right)
plot(states_ode45_K10[, "time"], states_ode45_K10[, "C"],
type = "l", xlim = c(0, 200), ylim = c(0, Cini), xlab = "Time", ylab = "CO2, g/m3", col = "black")
lines(states_ode45_K1[, "time"], states_ode45_K1[, "C"], col = "blue")
lines(states_ode45_K.1[, "time"], states_ode45_K.1[, "C"], col = "red")
plot(states_ode45_K10[, "C"], states_ode45_K10[, "P"],
type = "l", xlim = c(0, 10), ylim = c(0, 10E-4),
xlab = "Conc. CO2", ylab = "Rate of photosynthesis", lty = 1, lwd = 1, col = "black")
lines(states_ode45_K1[, "C"], states_ode45_K1[, "P"], lty = 1, lwd = 1, col = "blue")
lines(states_ode45_K.1[, "C"], states_ode45_K.1[, "P"], lty = 1, lwd = 1, col = "red")
plot(states_ode45_K10[, "time"], states_ode45_K10[, "TC"],
type = "l", xlim = c(0, 200), ylim = c(0, 200),
xlab = "Time", ylab = "Time coefficient", lty = 1, lwd = 1, col = "black")
lines(states_ode45_K1[, "time"], states_ode45_K1[, "TC"], lty = 1, lwd = 1, col = "blue")
lines(states_ode45_K.1[, "time"], states_ode45_K.1[, "TC"], lty = 1, lwd = 1, col = "red")
# add legend without a box
legend("right", legend = c("K = 10", "K = 1", "K = 0.1"),
col = c(" black", "blue", "red"), lty = c(1, 1, 1), bty = "n")
plot(states_ode45_K10[, "W"], states_ode45_K10[, "TC"],
type = "l", xlim = c(0, Volume * Cini), ylim = c(0, 200),
xlab = "W", ylab = "Time coefficient", lty = 1, lwd = 1, col = "black")
lines(states_ode45_K1[, "W"], states_ode45_K1[, "TC"], lty = 1, lwd = 1, col = "blue")
lines(states_ode45_K.1[, "W"], states_ode45_K.1[, "TC"], lty = 1, lwd = 1, col = "red")

The plot of chamber concentration C
versus time, which shows a decreasing pattern with the abscissa
(“x-axis”) as asymptote. The smaller the K-value, the steeper the curve. For a very
small value of K, an almost linear
decrease occurs until the CO2 is practically depleted. The
plot of P versus C shows the three hyperbolic Michaelis-Menten
relationships, as they evolve over the time of the simulation period.
There is a numerical problem connected with the fact that numerically
negative values of C may occur, even
though this is physically not possible. In the negative range of C the hyperbolic relationship has a vertical
asymptote at C=−K. For even more
negative values of C, the function
value becomes positive again other “leg” of the hyperbola).