## Put Equations in Divergence Form

### Coefficient Matching for Divergence Form

As explained in Equations You Can Solve Using Partial Differential Equation Toolbox, Partial Differential Equation Toolbox™ solvers address equations of the form

$$-\nabla \cdot \left(c\nabla u\right)+au=f$$

or variants that have derivatives with respect to time, or that
have eigenvalues, or are systems of equations. These equations are
in *divergence form*, where the differential
operator begins $$\nabla \xb7$$. The coefficients *a*, *c*,
and *f* are functions of position (*x*, *y*, *z*)
and possibly of the solution *u*.

However, you can have equations in a form with all the derivatives explicitly expanded, such as

$$\left(1+{x}^{2}\right)\frac{{\partial}^{2}u}{\partial {x}^{2}}-3xy\frac{{\partial}^{2}u}{\partial x\partial y}+\frac{\left(1+{y}^{2}\right)}{2}\frac{{\partial}^{2}u}{\partial {y}^{2}}=0$$

In order to transform this expanded equation into the required form, you can try to match the coefficients of the equation in divergence form to the expanded form. In divergence form, if

$$c=\left(\begin{array}{cc}{c}_{1}& {c}_{3}\\ {c}_{2}& {c}_{4}\end{array}\right)$$

then

$$\begin{array}{c}\nabla \xb7\left(c\nabla u\right)={c}_{1}{u}_{xx}+\left({c}_{2}+{c}_{3}\right){u}_{xy}+{c}_{4}{u}_{yy}\\ +\left(\frac{\partial {c}_{1}}{\partial x}+\frac{\partial {c}_{2}}{\partial y}\right){u}_{x}+\left(\frac{\partial {c}_{3}}{\partial x}+\frac{\partial {c}_{4}}{\partial y}\right){u}_{y}\end{array}$$

Matching coefficients in the *u _{xx}* and

*u*terms in $$-\nabla \cdot \left(c\nabla u\right)$$ to the equation, you get

_{yy}$$\begin{array}{l}{c}_{1}=-\left(1+{x}^{2}\right)\\ {c}_{4}=-\left(1+{y}^{2}\right)/2\end{array}$$

Then looking at the coefficients of *u _{x}* and

*u*, which should be zero, you get

_{y}$$\begin{array}{l}\left(\frac{\partial {c}_{1}}{\partial x}+\frac{\partial {c}_{2}}{\partial y}\right)=-2x+\frac{\partial {c}_{2}}{\partial y}\\ \text{so}\\ {c}_{2}=2xy.\\ \left(\frac{\partial {c}_{3}}{\partial x}+\frac{\partial {c}_{4}}{\partial y}\right)=\frac{\partial {c}_{3}}{\partial x}-y\\ \text{so}\\ {c}_{3}=xy\end{array}$$

This completes the conversion of the equation to the divergence form

$$-\nabla \cdot \left(c\nabla u\right)=0$$

### Boundary Conditions Can Affect the c Coefficient

The `c`

coefficient appears in the generalized
Neumann condition

$$\overrightarrow{n}\text{\hspace{0.17em}}\xb7\text{\hspace{0.17em}}\left(c\nabla u\right)+qu=g$$

So when you derive a divergence form of the `c`

coefficient,
keep in mind that this coefficient appears elsewhere.

For example, consider the 2-D Poisson equation –*u _{xx}* –

*u*=

_{yy}*f*. Obviously, you can take

*c*= 1. But there are other

*c*matrices that lead to the same equation: any that have

*c*(2) +

*c*(3) = 0.

$$\begin{array}{c}\nabla \text{\hspace{0.17em}}\xb7\text{\hspace{0.17em}}\left(c\nabla u\right)=\nabla \text{\hspace{0.17em}}\xb7\text{\hspace{0.17em}}\left(\left(\begin{array}{cc}{c}_{1}& {c}_{3}\\ {c}_{2}& {c}_{4}\end{array}\right)\left(\begin{array}{c}{u}_{x}\\ {u}_{y}\end{array}\right)\right)\\ =\frac{\partial}{\partial x}\left({c}_{1}{u}_{x}+{c}_{3}{u}_{y}\right)+\frac{\partial}{\partial y}\left({c}_{2}{u}_{x}+{c}_{4}{u}_{y}\right)\\ ={c}_{1}{u}_{xx}+{c}_{4}{u}_{yy}+\left({c}_{2}+{c}_{3}\right){u}_{xy}\end{array}$$

So there is freedom in choosing a *c* matrix.
If you have a Neumann boundary condition such as

$$\overrightarrow{n}\text{\hspace{0.17em}}\xb7\text{\hspace{0.17em}}\left(c\nabla u\right)=2$$

the boundary condition depends on which version of *c* you
use. In this case, make sure that you take a version of *c* that
is compatible with both the equation and the boundary condition.

### Coefficient Conversion with Symbolic Math Toolbox

You can transform a partial differential equation into the required form by using Symbolic Math Toolbox™. The toolbox offers these two functions to help with the conversion:

`pdeCoefficients`

(Symbolic Math Toolbox) converts a PDE into the required form and extracts the coefficients into a structure of double-precision numbers and function handles, which can be used by`specifyCoefficients`

. The`pdeCoefficients`

function also can return a structure of symbolic expressions, in which case you need to convert these expressions to double format before passing them to`specifyCoefficients`

.`pdeCoefficientsToDouble`

(Symbolic Math Toolbox) converts symbolic PDE coefficients to double format.

Solve Partial Differential Equation of Nonlinear Heat Transfer (Symbolic Math Toolbox) shows how the Symbolic Math Toolbox functions can help you convert a PDE to the required form. Nonlinear Heat Transfer in Thin Plate shows the same example without the use of Symbolic Math Toolbox.

### Some Equations Cannot Be Converted

Sometimes it is not possible to find a conversion to a divergence form such as

$$-\nabla \cdot \left(c\nabla u\right)+au=f$$

For example, consider the equation

$$\frac{{\partial}^{2}u}{\partial {x}^{2}}+\frac{\mathrm{cos}(x+y)}{4}\frac{{\partial}^{2}u}{\partial x\partial y}+\frac{1}{2}\frac{{\partial}^{2}u}{\partial {y}^{2}}=0$$

By simple coefficient matching, you see that the coefficients *c*_{1} and *c*_{4} are
–1 and –1/2 respectively. However, there are no *c*_{2} and *c*_{3} that
satisfy the remaining equations,

$$\begin{array}{c}{c}_{2}+{c}_{3}=\frac{-\mathrm{cos}(x+y)}{4}\\ \frac{\partial {c}_{1}}{\partial x}+\frac{\partial {c}_{2}}{\partial y}=\frac{\partial {c}_{2}}{\partial y}=0\\ \frac{\partial {c}_{3}}{\partial x}+\frac{\partial {c}_{4}}{\partial y}=\frac{\partial {c}_{3}}{\partial x}=0\end{array}$$