假设我们有一个pde,它描述了变量y(t,x)随时间t和空间x的演变,我想在三维图(t,x,y)上画出它的演化图。使用deSolve,我可以解决这个问题,但我不知道如何获得这样的图。
deSolve包指令中的示例如下,其中y是蚜虫、t=0、...,200和x=1,...,60:
library(deSolve)
Aphid <- function(t, APHIDS, parameters) {
deltax <- c (0.5, rep(1, numboxes - 1), 0.5)
Flux <- -D * diff(c(0, APHIDS, 0)) / deltax
dAPHIDS <- -diff(Flux) / delx + APHIDS * r
list(dAPHIDS )
}
D <- 0.3 # m2/day diffusion rate
r <- 0.01 # /day net growth rate
delx <- 1 # m thickness of boxes
numboxes <- 60
Distance <- seq(from = 0.5, by = delx, length.out = numboxes)
APHIDS <- rep(0, times = numboxes)
APHIDS[30:31] <- 1
state <- c(APHIDS = APHIDS) # initialise state variables
times <-seq(0, 200, by = 1)
out <- ode.1D(state, times, Aphid, parms = 0, nspec = 1, names = "Aphid")"out“生成一个包含我们需要的所有数据的矩阵,t,y(x1),y(x2),.y(x60).如何生成表面图来显示y在(t,x)中的演化和可变性?
发布于 2016-09-25 08:07:18
根据使用包的不同,方式也会发生一些变化。但是你可以用很小的成本完成它,因为out[,-1]是绘制曲面的理想的矩阵形式。我展示了两个使用rgl和plot3D包的示例。
out2 <- out[,-1]
AphID <- 1:ncol(out2)
library(rgl)
persp3d(times, AphID, out2, col="gray50", zlab="y")
# If you want to change color with value of Z-axis
# persp3d(times, AphID, out2, zlab="y", col=topo.colors(256)[cut(c(out2), 256)])
library(plot3D)
mat <- mesh(times, AphID)
surf3D(mat$x, mat$y, out2, bty="f", ticktype="detailed", xlab="times", ylab="AphID", zlab="y")

https://stackoverflow.com/questions/39682361
复制相似问题