Hello everyone,
   I am trying to solve 2D differential equations using finite difference
scheme in R. I have been able to work with the equations with only one
spatial dimensions but I want to extend it to the two dimensional problem.
For example i can simulate one dimensional diffusion using a code like the
following. But I want to write a similar code for,say, a two dimensional
diffusion equation. Any kind of help/advice is highly appreciated.

Here is how I did for the 1D equation (in this case for 1D diffusion)
Equation: dc/dt  = D*d^2c/dx^2


dx = 10
dt = 0.1
D = 15
n = 20
tstep = 200
C = 50
dt = 0.1
dx = 10
conc<-matrix(0,tstep,n)
conc[1,1:10] = C
 for (i in 2:tstep) {
for (j in 1:n){
if (j==1){
conc[i,j] = conc[i-1,j] - dt*(D/dx^2)*(conc[i-1,j] - conc[i-1,j+1])
}
conc[i,j] = conc[i,j]
 if(j >1 && j < n){
conc[i,j] = conc[i-1,j] + dt*(D/dx^2)* (conc[i-1,(j-1)] - 2*conc[i-1,j] +
conc[i-1,(j+1)])
}
if (j==n){
conc[i,n] = conc[i-1,n] + dt*(D/dx^2)* ( conc[i-1,n-1] - conc[i-1,n])
}
conc[i,j] = conc[i,j]
}
}

Now in 2D the equation will be like this

dc/dt  = Dx*d^2c/dx^2 + Dy*d^C/dy^2

So that when I solve it I will get C(x, y, t) at each node of the grid.

Thanks for the help in advance.
-- 
Acharya, Subodh

	[[alternative HTML version deleted]]

