# Solve System of PDEs with Initial Condition Step Functions

This example shows how to solve a system of partial differential equations that uses step functions in the initial conditions.

Consider the PDEs

`$\begin{array}{l}\frac{\partial \mathit{n}}{\partial \mathit{t}}=\frac{\partial }{\partial \mathit{x}}\left[\mathit{d}\frac{\partial \mathit{n}}{\partial \mathit{x}}-\mathit{a}\text{\hspace{0.17em}}\mathit{n}\frac{\partial \mathit{c}}{\partial \mathit{x}}\right]+\mathit{S}\text{\hspace{0.17em}}\mathit{r}\text{\hspace{0.17em}}\mathit{n}\left(\mathit{N}-\mathit{n}\right),\\ \frac{\partial \mathit{c}}{\partial \mathit{t}}=\frac{{\partial }^{2}\mathit{c}}{\partial {\mathit{x}}^{2}}+\mathit{S}\left(\frac{\mathit{n}}{\mathit{n}+1}-\mathit{c}\right).\end{array}$`

The equations involve the constant parameters $\mathit{d}$, $\mathit{a}$, $\mathit{S}$, $\mathit{r}$, and $\mathit{N}$, and are defined for $0\le \mathit{x}\le 1$ and $\mathit{t}\ge 0$. These equations arise in a mathematical model of the first steps of tumor-related angiogenesis [1]. $\mathit{n}\left(\mathit{x},\mathit{t}\right)$ represents the cell density of endothelial cells, and $\mathit{c}\left(\mathit{x},\mathit{t}\right)$ the concentration of a protein they release in response to the tumor.

This problem has a constant, steady state when

$\left[\begin{array}{c}{\mathit{n}}_{0}\\ {\mathit{c}}_{0}\end{array}\right]=\left[\begin{array}{c}1\\ 0.5\end{array}\right]$.

However, a stability analysis predicts evolution of the system to an inhomogeneous solution [1]. So step functions are used as the initial conditions to perturb the steady state and stimulate evolution of the system.

The boundary conditions require that both solution components have zero flux at $\mathit{x}=0$ and $\mathit{x}=1$.

`$\begin{array}{l}\frac{\partial }{\partial \mathit{x}}\mathit{n}\left(0,\mathit{t}\right)=\frac{\partial }{\partial \mathit{x}}\mathit{n}\left(1,\mathit{t}\right)=0,\\ \frac{\partial }{\partial \mathit{x}}\mathit{c}\left(0,\mathit{t}\right)=\frac{\partial }{\partial \mathit{x}}\mathit{c}\left(1,\mathit{t}\right)=0.\end{array}$`

To solve this system of equations in MATLAB®, you need to code the equations, initial conditions, and boundary conditions, then select a suitable solution mesh before calling the solver `pdepe`. You either can include the required functions as local functions at the end of a file (as done here), or save them as separate, named files in a directory on the MATLAB path.

### Code Equation

Before you can code the equation, you need to make sure that it is in the form that the `pdepe` solver expects:

`$\mathit{c}\left(\mathit{x},\mathit{t},\mathit{u},\frac{\partial \mathit{u}}{\partial \mathit{x}}\right)\frac{\partial \mathit{u}}{\partial \mathit{t}}={\mathit{x}}^{-\mathit{m}}\frac{\partial }{\partial \mathit{x}}\left({\mathit{x}}^{\mathit{m}}\mathit{f}\left(\mathit{x},\mathit{t},\mathit{u},\frac{\partial \mathit{u}}{\partial \mathit{x}}\right)\right)+\mathit{s}\left(\mathit{x},\mathit{t},\mathit{u},\frac{\partial \mathit{u}}{\partial \mathit{x}}\right).$`

Since there are two equations in the system of PDEs, the system of PDEs can be rewritten as

`$\left[\begin{array}{cc}1& 0\\ 0& 1\end{array}\right]\frac{\partial }{\partial \mathit{t}}\left[\begin{array}{c}\mathit{n}\\ \mathit{c}\end{array}\right]=\frac{\partial }{\partial \mathit{x}}\left[\begin{array}{c}\mathit{d}\frac{\partial \mathit{n}}{\partial \mathit{x}}-\mathit{a}\text{\hspace{0.17em}}\mathit{n}\frac{\partial \mathit{c}}{\partial \mathit{x}}\\ \frac{\partial \mathit{c}}{\partial \mathit{x}}\end{array}\right]+\left[\begin{array}{c}\mathit{S}\text{\hspace{0.17em}}\mathit{r}\text{\hspace{0.17em}}\mathit{n}\left(\mathit{N}-\mathit{n}\right)\\ \mathit{S}\left(\frac{\mathit{n}}{\mathit{n}+1}-\mathit{c}\right)\end{array}\right].$`

The values of the coefficients in the equation are then

`$\mathit{m}=0$`

$\mathit{c}\left(\mathit{x},\mathit{t},\mathit{u},\frac{\partial \mathit{u}}{\partial \mathit{x}}\right)=\left[\begin{array}{c}1\\ 1\end{array}\right]$ (diagonal values only)

`$\mathit{f}\left(\mathit{x},\mathit{t},\mathit{u},\frac{\partial \mathit{u}}{\partial \mathit{x}}\right)=\left[\begin{array}{c}\mathit{d}\frac{\partial \mathit{n}}{\partial \mathit{x}}-\mathit{a}\text{\hspace{0.17em}}\mathit{n}\frac{\partial \mathit{c}}{\partial \mathit{x}}\\ \frac{\partial \mathit{c}}{\partial \mathit{x}}\end{array}\right]$`

`$\mathit{s}\left(\mathit{x},\mathit{t},\mathit{u},\frac{\partial \mathit{u}}{\partial \mathit{x}}\right)=\left[\begin{array}{c}\mathit{S}\text{\hspace{0.17em}}\mathit{r}\text{\hspace{0.17em}}\mathit{n}\left(\mathit{N}-\mathit{n}\right)\\ \mathit{S}\left(\frac{\mathit{n}}{\mathit{n}+1}-\mathit{c}\right)\end{array}\right]$`

Now you can create a function to code the equation. The function should have the signature `[c,f,s] = angiopde(x,t,u,dudx)`:

• `x` is the independent spatial variable.

• `t` is the independent time variable.

• `u` is the dependent variable being differentiated with respect to `x` and `t`. It is a two-element vector where `u(1)` is $\mathit{n}\left(\mathit{x},\mathit{t}\right)$ and `u(2)` is $\mathit{c}\left(\mathit{x},\mathit{t}\right)$.

• `dudx` is the partial spatial derivative $\partial \mathit{u}/\partial \mathit{x}$. It is a two-element vector where `dudx(1)` is $\partial \mathit{n}/\partial \mathit{x}$ and `dudx(2)` is $\partial \mathit{c}/\partial \mathit{x}$.

• The outputs `c`, `f`, and `s` correspond to coefficients in the standard PDE equation form expected by `pdepe`.

As a result, the equations in this example can be represented by the function:

```function [c,f,s] = angiopde(x,t,u,dudx) d = 1e-3; a = 3.8; S = 3; r = 0.88; N = 1; c = [1; 1]; f = [d*dudx(1) - a*u(1)*dudx(2) dudx(2)]; s = [S*r*u(1)*(N - u(1)); S*(u(1)/(u(1) + 1) - u(2))]; end ```

(Note: All functions are included as local functions at the end of the example.)

### Code Initial Conditions

Next, write a function that returns the initial condition. The initial condition is applied at the first time value and provides the value of $\mathit{n}\left(\mathit{x},{\mathit{t}}_{0}\right)$ and $\mathit{c}\left(\mathit{x},{\mathit{t}}_{0}\right)$ for any value of x. Use the function signature `u0 = angioic(x)` to write the function.

This problem has a constant, steady state when

$\left[\begin{array}{c}{\mathit{n}}_{0}\\ {\mathit{c}}_{0}\end{array}\right]=\left[\begin{array}{c}1\\ 0.5\end{array}\right]$.

However, a stability analysis predicts evolution of the system to an inhomogenous solution [1]. So, step functions are used as the initial conditions to perturb the steady state and stimulate evolution of the system.

`$\begin{array}{l}\mathit{u}\left(\mathit{x},0\right)=\left[\begin{array}{c}{\mathit{n}}_{0}\\ {\mathit{c}}_{0}\end{array}\right],\\ \mathit{u}\left(\mathit{x},0\right)=\left\{\begin{array}{cc}1.05{\mathit{u}}_{1}\text{\hspace{0.17em}}& 0.3\le \mathit{x}\le 0.6\\ 1.0005{\mathit{u}}_{2}& 0.3\le \mathit{x}\le 0.6\end{array}\end{array}$`

The corresponding function is

```function u0 = angioic(x) u0 = [1; 0.5]; if x >= 0.3 && x <= 0.6 u0(1) = 1.05 * u0(1); u0(2) = 1.0005 * u0(2); end end ```

### Code Boundary Conditions

Now, write a function that evaluates the boundary conditions

`$\begin{array}{l}\frac{\partial }{\partial \mathit{x}}\mathit{n}\left(0,\mathit{t}\right)=\frac{\partial }{\partial \mathit{x}}\mathit{n}\left(1,\mathit{t}\right)=0,\\ \frac{\partial }{\partial \mathit{x}}\mathit{c}\left(0,\mathit{t}\right)=\frac{\partial }{\partial \mathit{x}}\mathit{c}\left(1,\mathit{t}\right)=0.\end{array}$`

For problems posed on the interval $\mathit{a}\le \mathit{x}\le \mathit{b}$, the boundary conditions apply for all $\mathit{t}$ and either $\mathit{x}=\mathit{a}$ or $\mathit{x}=\mathit{b}$. The standard form for the boundary conditions expected by the solver is

`$\mathit{p}\left(\mathit{x},\mathit{t},\mathit{u}\right)+\mathit{q}\left(\mathit{x},\mathit{t}\right)\mathit{f}\left(\mathit{x},\mathit{t},\mathit{u},\frac{\partial \mathit{u}}{\partial \mathit{x}}\right)=0.$`

For $\mathit{x}=0$, the boundary condition equation is

`$\left[\begin{array}{c}0\\ 0\end{array}\right]+\left[\begin{array}{c}1\\ 1\end{array}\right]\cdot \left[\begin{array}{c}\mathit{d}\frac{\partial \mathit{n}}{\partial \mathit{x}}-\mathit{a}\text{\hspace{0.17em}}\mathit{n}\frac{\partial \mathit{c}}{\partial \mathit{x}}\\ \frac{\partial \mathit{c}}{\partial \mathit{x}}\end{array}\right]=0.$`

So the coefficients are:

• ${\mathit{p}}_{\mathit{L}}\left(\mathit{x},\mathit{t},\mathit{u}\right)=\left[\begin{array}{c}0\\ 0\end{array}\right],$

• ${\mathit{q}}_{\mathit{L}}\left(\mathit{x},\mathit{t}\right)=\left[\begin{array}{c}1\\ 1\end{array}\right]$.

For $\mathit{x}=1$ the boundary conditions are the same, so ${\mathit{p}}_{\mathit{R}}\left(\mathit{x},\mathit{t},\mathit{u}\right)=\left[\begin{array}{c}0\\ 0\end{array}\right]$ and ${\mathit{q}}_{\mathit{R}}\left(\mathit{x},\mathit{t}\right)=\left[\begin{array}{c}1\\ 1\end{array}\right]$.

The boundary function should use the function signature `[pl,ql,pr,qr] = angiobc(xl,ul,xr,ur,t)`, where:

• The inputs `xl` and `ul` correspond to $\mathit{u}$ and $\mathit{x}$ for the left boundary.

• The inputs `xr` and `ur` correspond to $\mathit{u}$ and $\mathit{x}$ for the right boundary.

• `t` is the independent time variable.

• The outputs `pl` and `ql` correspond to ${\mathit{p}}_{\mathit{L}}\left(\mathit{x},\mathit{t},\mathit{u}\right)$ and ${\mathit{q}}_{\mathit{L}}\left(\mathit{x},\mathit{t}\right)$ for the left boundary ($\mathit{x}=0$ for this problem).

• The outputs `pr` and `qr` correspond to ${\mathit{p}}_{\mathit{R}}\left(\mathit{x},\mathit{t},\mathit{u}\right)$ and ${\mathit{q}}_{\mathit{R}}\left(\mathit{x},\mathit{t}\right)$ for the right boundary ($\mathit{x}=1$ for this problem).

The boundary conditions in this example are represented by the function:

```function [pl,ql,pr,qr] = angiobc(xl,ul,xr,ur,t) pl = [0; 0]; ql = [1; 1]; pr = pl; qr = ql; end ```

### Select Solution Mesh

A long time interval is required to see the limiting behavior of the equations, so use 10 points in the interval $0\le \mathit{t}\le 200$. Also, the limit distribution of $\mathit{c}\left(\mathit{x},\mathit{t}\right)$ varies by only about 0.1% over the interval $0\le \mathit{x}\le 1$, so a relatively fine spatial mesh with 50 points is appropriate.

```x = linspace(0,1,50); t = linspace(0,200,10);```

### Solve Equation

Finally, solve the equation using the symmetry $\mathit{m}$, the PDE equation, the initial condition, the boundary conditions, and the meshes for $\mathit{x}$ and $\mathit{t}$.

```m = 0; sol = pdepe(m,@angiopde,@angioic,@angiobc,x,t);```

`pdepe` returns the solution in a 3-D array `sol`, where `sol(i,j,k)` approximates the `k`th component of the solution ${\mathit{u}}_{\mathit{k}}$ evaluated at `t(i)` and `x(j)`. Extract the solution components into separate variables.

```n = sol(:,:,1); c = sol(:,:,2);```

### Plot Solution

Create a surface plot of the solution components $\mathit{n}$ and $\mathit{c}$ plotted at the selected mesh points for $\mathit{x}$ and $\mathit{t}$.

```surf(x,t,c) title('c(x,t): Concentration of Fibronectin') xlabel('Distance x') ylabel('Time t')```

```surf(x,t,n) title('n(x,t): Density of Endothelial Cells') xlabel('Distance x') ylabel('Time t')```

Now plot just the final distributions of the solutions at ${\mathit{t}}_{\mathit{f}}=200$. These plots correspond to Figures 3 and 4 in [1].

```plot(x,n(end,:)) title('Final distribution of n(x,t_f)')```

```plot(x,c(end,:)) title('Final distribution of c(x,t_f)')```

### References

[1] Humphreys, M.E. and M.A.J. Chaplain. "A mathematical model of the first steps of tumour-related angiogenesis: Capillary sprout formation and secondary branching." IMA Journal of Mathematics Applied in Medicine & Biology, 13 (1996), pp. 73-98.

### Local Functions

Listed here are the local helper functions that the PDE solver pdepe calls to calculate the solution. Alternatively, you can save these functions as their own files in a directory on the MATLAB path.

```function [c,f,s] = angiopde(x,t,u,dudx) % Equation to solve d = 1e-3; a = 3.8; S = 3; r = 0.88; N = 1; c = [1; 1]; f = [d*dudx(1) - a*u(1)*dudx(2) dudx(2)]; s = [S*r*u(1)*(N - u(1)); S*(u(1)/(u(1) + 1) - u(2))]; end % --------------------------------------------- function u0 = angioic(x) % Initial Conditions u0 = [1; 0.5]; if x >= 0.3 && x <= 0.6 u0(1) = 1.05 * u0(1); u0(2) = 1.0005 * u0(2); end end % --------------------------------------------- function [pl,ql,pr,qr] = angiobc(xl,ul,xr,ur,t) % Boundary Conditions pl = [0; 0]; ql = [1; 1]; pr = pl; qr = ql; end % ---------------------------------------------```