我想运行解决&将我的ode解决方案绘制到以下三个不同的时间,每次都要处理一个初始条件。我想解决q.0 = 16,q.0 = 20,q.0 = 18。
(如果将其全部绘制在矩阵中会很好..!提前致谢)
rm(list = ls())
par(mfrow = c(1,1))
D = 6 ; A = pi* D^2 / 4 ;
# ODE solver
library(deSolve)
parameters <- c(A,
k = (16/sqrt(5)),
q.0 = 16,
h.0 = 5
)
state <- c(h = 5)
Model <- function(t, state, parameters) {
with(as.list(c(state, parameters)),{
# rate of change
dh <- q.0/A - k/A * h^(1/2)
# return the rate of change
list(c(dh))
}) # end with(as.list ...
}
times <- seq(0, 100, 1)
out <- ode(y = state, times = times, func = Model, parms = parameters)
par(oma = c(0, 0, 3, 0))
plot(out, xlab = "time", ylab = "-")
plot(out[, "time"], out[, "h"], pch = ".",
xlab = "time [h]",
ylab = "Height [ft]")
mtext(outer = TRUE, side = 3, "Variable Holdup Tank Model", cex = 1.5)
write.table(out, "mydataCSTR.txt", sep="\t")
答案 0 :(得分:-1)
或者,并且确实仍然有点简单:将其运行为q.0的第一个值,但使用lines
绘制其他两个运行,以便您可以在同一图表上看到所有三个解决方案。