2016-09-25 2 views
1

angenommen, dass wir ein pde haben, das die Entwicklung einer Variablen y (t, x) über die Zeit t und den Raum x beschreibt, und ich möchte seine Entwicklung in einem dreidimensionalen Diagramm darstellen (t, x, y). Mit deSolve kann ich die PDE lösen, aber ich habe keine Ahnung, wie man diese Art von Diagramm erhält.r deSolve - Entwicklungszeit Entwicklung pde

Das Beispiel in dem Paket deSolve Anweisung ist die folgende, wobei y Blattläuse, t = 0, ..., 200 und 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" erzeugt eine Matrix, die alle Daten enthält, die wir brauchen, t, y (x1), y (x2), ... y (x60). Wie kann ich ein Oberflächendiagramm erstellen, um die Entwicklung und Variabilität von y in (t, x) zu zeigen?

Antwort

0

Die Wege ändern sich ein wenig abhängig von der Verwendung von Paket. Aber Sie können es mit wenig Kosten tun, weil out[,-1] eine ideale Matrixform ist, um Oberfläche zu zeichnen. Ich habe zwei Beispiele mit rgl und plot3D Paket gezeigt.

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") 

enter image description here

Verwandte Themen