求解R

时间:2017-12-07 10:26:47

标签: r pde

我需要解决以下在R中包含扩散项的PDE系统

The model

我使用R包ReacTran来解决上述系统。这是我的R代码:

library(ReacTran)
library(deSolve)
library(rgl)

# Parameters
r <- 1
epsilon <- 1
delta <- 0.1
a_P <- 5
b_P <- 0.1
a_I <- 0.1
b_I <- 0.01
D_C <- 0.00001
D_I <- 0.001

# Gaussian membership function
gaussmf <- function(x, mu, sigma) { 
  return(exp(-((x - mu) ^ 2) / (2 * (sigma ^ 2))))
}

# Discretization of spatial variable
xgrid <- setup.grid.1D(x.up = 0, x.down = 2, N = 200)

# System of PDE's
system<-function(t, state, parameters) {
  with(as.list(c(state, parameters)),{

    dC <- ((r * C) / (epsilon * C + 1)) * (P / (I + 1)) - delta * C + tran.1D(C = C, D = D_C, dx = xgrid)$dC
    dP <- (a_P * C) - (b_P * P)
    dI <- (a_I * C) - (b_I * I) + tran.1D(C = I, D = D_I, dx = xgrid)$dC

    list(c(dC, dP, dI))})
}

# Setting parameters
parameters <- list(r = r, epsilon = epsilon, delte = delta, a_P = a_P, b_P = b_P, a_I = a_I, b_I = b_I)

# Setting initial values

C <- gaussmf(xgrid$x.mid, mu = 1, sigma = 0.02)
P <- rep(0, times =  xgrid$N)
I <- rep(0, times =  xgrid$N)

state <- c(C = C, P = P, I = I)

# Setting time steps
times <- seq(0, 100, by = 1)

# Solving the system
out <- ode.1D(y = state, times = times, func = system, parms = parameters, dimens = xgrid$N)

# Plotting the result
persp3d(x=times, y=xgrid$x.mid, z=out[,2:(xgrid$N+1)],col = "skyblue",xlab = "Time", ylab = "Location", zlab = "C")

我已经通过MATLABs pdepe函数解决了这个系统,我得到了理想的结果。但是通过在R中运行上面的代码,我得不到正确的结果(比如MATLAB)。似乎扩散术语不起作用。这有什么问题?

修改

实际上我应该得到以下参数a_I的不同值的曲线:

对于a_I = 3:

a_I=3

对于a_I = 2:

a_I=2

对于a_I = 1:

a_I=1

对于a_I = 0.1:

a_I=0.1

纵轴表示C的值,横轴表示空间变量x。

0 个答案:

没有答案