solving PDEs in MATLAB

I want to solve 3 coupled equations. I converted them to a system of odes in time and discrete it in Length and radius. Now I have a problem in one of the equations in first point. Because in this point I have A second order derivative and when I discretize it I dont have $y$ in second point. This is my equation:

$\frac{dy}{dy} = \frac{d^{2}y}{dr^{2}}+k(y-q)$.

This is the discretized form in matlab:

$\frac{dy}{dt} = \frac{y(i+2)-2y(i+1)+y(i)}{\Delta{r}^{2}}+k(y(i)-q(i))$

Now in $i=1$ we dont have points $2$ and $3$ and they will calculate in next line in MATLAB. What should I do?

• The important omission here is that you don't state what your boundary conditions are. – Wolfgang Bangerth Dec 28 '15 at 17:47

Your problems is with $y(i+2)$ ? You have to first put some initial conditiones, witch would be y(0)....y(n). Besides the boundarys.

Imagine if you were solving waves in a string. The initial conditions would be the shape of the string... Hence $y(r,t=0)=f(r)$ . That when discretized give the initial values for $y(i+1)$ and $y(i+2)$ .

I assume you are solving an initial-value problem, so that $y(r, t=0)$ is known. Your temporal discretization will determine what to do -- for example, using forward Euler, you would get: $$y(r, t+\delta t) = y(r,t) + \delta \, f(y(r,t)),$$ where $f$ represents you right-hand side. This is the simplest explicit scheme, see this explanation, which you probably should not use in practice. There are many alternatives, e.g. Runge-Kutta methods.