# Note: Example 3 below may take several minutes to run. Patience is required!
# Example 1: calculating a single derivative using a soybean model
soybean_system <- system_derivatives(
soybean$parameters,
soybean_weather$'2002',
soybean$direct_modules,
soybean$differential_modules
)
derivs <- soybean_system(0, unlist(soybean$initial_values), NULL)
# Example 2: a simple oscillator with only one module
times = seq(0, 5, by = 1) # times spaced by `timestep`
oscillator_system_derivatives <- system_derivatives(
list(
timestep = 1,
mass = 1,
spring_constant = 1
),
data.frame(time = times),
c(),
'BioCro:harmonic_oscillator'
)
result <- as.data.frame(deSolve::lsodes(
c(position=0, velocity=1),
times,
oscillator_system_derivatives
))
lattice::xyplot(
position + velocity ~ time,
type='l',
auto=TRUE,
data=result
)
# Example 3: solving 500 hours of a soybean simulation. This will run slowly
# compared to a regular call to `run_biocro`.
# \donttest{
soybean_system <- system_derivatives(
soybean$parameters,
soybean_weather$'2002',
soybean$direct_modules,
soybean$differential_modules
)
times = seq(from=0, to=500, by=1)
result <- as.data.frame(deSolve::lsodes(unlist(soybean$initial_values), times, soybean_system))
lattice::xyplot(Leaf + Stem ~ time, type='l', auto=TRUE, data=result)
# }
Run the code above in your browser using DataLab