Accelerating the pace of engineering and science

# Documentation

## c for Systems

### c as Tensor, Matrix, and Vector

This section describes how to write the coefficient c in the equation

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

or in similar equations. The coefficient c is an N-by-N-by-2-by-2 tensor with components c(i,j,k,l). N is the number of equations, see Systems of PDEs.

The notation $\nabla \cdot \left(c\otimes \nabla u\right)$ means the N-by-1 matrix with (i,1)-component.

$\sum _{j=1}^{N}\left(\frac{\partial }{\partial x}{c}_{i,j,1,1}\frac{\partial }{\partial x}+\frac{\partial }{\partial x}{c}_{i,j,1,2}\frac{\partial }{\partial y}+\frac{\partial }{\partial y}{c}_{i,j,2,1}\frac{\partial }{\partial x}+\frac{\partial }{\partial y}{c}_{i,j,2,2}\frac{\partial }{\partial y}\right){u}_{j}$

There are many ways to represent the coefficient c. All representations begin with a "flattening" of the N-by-N-by-2-by-2 tensor to a 2N-by-2N matrix, where the matrix is logically an N-by-N matrix of 2-by-2 blocks.

$\left(\begin{array}{ccccccccc}c\left(1,1,1,1\right)& c\left(1,1,1,2\right)& & c\left(1,2,1,1\right)& c\left(1,2,1,2\right)& & \cdots & c\left(1,N,1,1\right)& c\left(1,N,1,2\right)\\ c\left(1,1,2,1\right)& c\left(1,1,2,2\right)& & c\left(1,2,2,1\right)& c\left(1,2,2,2\right)& & \cdots & c\left(1,N,2,1\right)& c\left(1,N,2,2\right)\\ & & & & & & & & \\ c\left(2,1,1,1\right)& c\left(2,1,1,2\right)& & c\left(2,2,1,1\right)& c\left(2,2,1,2\right)& & \cdots & c\left(2,N,1,1\right)& c\left(2,N,1,2\right)\\ c\left(2,1,2,1\right)& c\left(2,1,2,2\right)& & c\left(2,2,2,1\right)& c\left(2,2,2,2\right)& & \cdots & c\left(2,N,2,1\right)& c\left(2,N,2,2\right)\\ & & & & & & & & \\ ⋮& ⋮& & ⋮& ⋮& & \ddots & ⋮& ⋮\\ c\left(N,1,1,1\right)& c\left(N,1,1,2\right)& & c\left(N,2,1,1\right)& c\left(N,2,1,2\right)& & \cdots & c\left(N,N,1,1\right)& c\left(N,N,1,2\right)\\ c\left(N,1,2,1\right)& c\left(N,1,2,2\right)& & c\left(N,2,2,1\right)& c\left(N,2,2,2\right)& & \cdots & c\left(N,N,2,1\right)& c\left(N,N,2,2\right)\end{array}\right)$

The matrix further gets flattened to a vector, where the N-by-N matrix of 2-by-2 blocks is first transformed to a "vector" of 2-by-2 blocks, and then the 2-by-2 blocks are turned into vectors in the usual column-wise way.

The coefficient vector c relates to the tensor c as follows:

$\left(\begin{array}{ccccccccc}c\left(1\right)& c\left(3\right)& & c\left(2N+1\right)& c\left(2N+3\right)& & \cdots & c\left(2N\left(2N-1\right)+1\right)& c\left(2N\left(2N-1\right)+3\right)\\ c\left(2\right)& c\left(4\right)& & c\left(2N+2\right)& c\left(2N+4\right)& & \cdots & c\left(2N\left(2N-1\right)+2\right)& c\left(2N\left(2N-1\right)+4\right)\\ & & & & & & & & \\ c\left(5\right)& c\left(7\right)& & c\left(2N+5\right)& c\left(2N+7\right)& & \cdots & c\left(2N\left(2N-1\right)+5\right)& c\left(2N\left(2N-1\right)+7\right)\\ c\left(6\right)& c\left(8\right)& & c\left(2N+6\right)& c\left(2N+8\right)& & \cdots & c\left(2N\left(2N-1\right)+6\right)& c\left(2N\left(2N-1\right)+8\right)\\ & & & & & & & & \\ ⋮& ⋮& & ⋮& ⋮& & \ddots & ⋮& ⋮\\ c\left(2N-3\right)& c\left(2N-1\right)& & c\left(4N-3\right)& c\left(4N-1\right)& & \cdots & c\left(4{N}^{2}-3\right)& c\left(4{N}^{2}-1\right)\\ c\left(2N-2\right)& c\left(2N\right)& & c\left(4N-2\right)& c\left(4N\right)& & \cdots & c\left(4{N}^{2}-2\right)& c\left(4{N}^{2}\right)\end{array}\right)$

Coefficient c(i,j,k,l) is in row (4N(j–1)+4i+2l+k–6) of the vector c.

Express c as numbers, text expressions, or functions, as in f for Systems.

Often, your tensor c has structure, such as symmetric or block diagonal. In many cases, you can represent c using a smaller vector than one with 4N2 components.

The number of rows in the matrix can differ from 4N2, as described in the next few sections.

In function form, the number of columns is Nt, which is the number of triangles in the mesh. The function should evaluate c at the triangle centroids, as in Scalar PDE Coefficients in Function Form. Give solvers the function name as a string 'filename', or as a function handle @filename, where filename.m is a file on your MATLAB® path. For details on writing the function, see Calculate Coefficients in Function Form.

### Scalar c

The software interprets a scalar c as a diagonal matrix, with c(i,i,1,1) and c(i,i,2,2) equal to the scalar, and all other entries 0.

$\left(\begin{array}{ccccccccc}c& 0& & 0& 0& & \cdots & 0& 0\\ 0& c& & 0& 0& & \cdots & 0& 0\\ & & & & & & & & \\ 0& 0& & c& 0& & \cdots & 0& 0\\ 0& 0& & 0& c& & \cdots & 0& 0\\ & & & & & & & & \\ ⋮& ⋮& & ⋮& ⋮& & \ddots & ⋮& ⋮\\ 0& 0& & 0& 0& & \cdots & c& 0\\ 0& 0& & 0& 0& & \cdots & 0& c\end{array}\right)$

### Two-Element Column Vector c

The software interprets a two-element column vector c as a diagonal matrix, with c(i,i,1,1) and c(i,i,2,2) as the two entries, and all other entries 0.

$\left(\begin{array}{ccccccccc}c\left(1\right)& 0& & 0& 0& & \cdots & 0& 0\\ 0& c\left(2\right)& & 0& 0& & \cdots & 0& 0\\ & & & & & & & & \\ 0& 0& & c\left(1\right)& 0& & \cdots & 0& 0\\ 0& 0& & 0& c\left(2\right)& & \cdots & 0& 0\\ & & & & & & & & \\ ⋮& ⋮& & ⋮& ⋮& & \ddots & ⋮& ⋮\\ 0& 0& & 0& 0& & \cdots & c\left(1\right)& 0\\ 0& 0& & 0& 0& & \cdots & 0& c\left(2\right)\end{array}\right)$

### Three-Element Column Vector c

The software interprets a three-element column vector c as a symmetric block diagonal matrix, with c(i,i,1,1) = c(1), c(i,i,2,2) = c(3), and c(i,i,1,2) = c(i,i,2,1) = c(2).

$\left(\begin{array}{ccccccccc}c\left(1\right)& c\left(2\right)& & 0& 0& & \cdots & 0& 0\\ c\left(2\right)& c\left(3\right)& & 0& 0& & \cdots & 0& 0\\ & & & & & & & & \\ 0& 0& & c\left(1\right)& c\left(2\right)& & \cdots & 0& 0\\ 0& 0& & c\left(2\right)& c\left(3\right)& & \cdots & 0& 0\\ & & & & & & & & \\ ⋮& ⋮& & ⋮& ⋮& & \ddots & ⋮& ⋮\\ 0& 0& & 0& 0& & \cdots & c\left(1\right)& c\left(2\right)\\ 0& 0& & 0& 0& & \cdots & c\left(2\right)& c\left(3\right)\end{array}\right)$

### Four-Element Column Vector c

The software interprets a four-element column vector c as a block diagonal matrix.

$\left(\begin{array}{ccccccccc}c\left(1\right)& c\left(3\right)& & 0& 0& & \cdots & 0& 0\\ c\left(2\right)& c\left(4\right)& & 0& 0& & \cdots & 0& 0\\ & & & & & & & & \\ 0& 0& & c\left(1\right)& c\left(3\right)& & \cdots & 0& 0\\ 0& 0& & c\left(2\right)& c\left(4\right)& & \cdots & 0& 0\\ & & & & & & & & \\ ⋮& ⋮& & ⋮& ⋮& & \ddots & ⋮& ⋮\\ 0& 0& & 0& 0& & \cdots & c\left(1\right)& c\left(3\right)\\ 0& 0& & 0& 0& & \cdots & c\left(2\right)& c\left(4\right)\end{array}\right)$

### N-Element Column Vector c

The software interprets an N-element column vector c as a diagonal matrix.

$\left(\begin{array}{ccccccccc}c\left(1\right)& 0& & 0& 0& & \cdots & 0& 0\\ 0& c\left(1\right)& & 0& 0& & \cdots & 0& 0\\ & & & & & & & & \\ 0& 0& & c\left(2\right)& 0& & \cdots & 0& 0\\ 0& 0& & 0& c\left(2\right)& & \cdots & 0& 0\\ & & & & & & & & \\ ⋮& ⋮& & ⋮& ⋮& & \ddots & ⋮& ⋮\\ 0& 0& & 0& 0& & \cdots & c\left(N\right)& 0\\ 0& 0& & 0& 0& & \cdots & 0& c\left(N\right)\end{array}\right)$

 Caution   If N = 2, 3, or 4, the 2-, 3-, or 4-element column vector form takes precedence over the N-element form. So, for example, if N = 3, and you have a c matrix of the form$\left(\begin{array}{cccccc}c1& 0& 0& 0& 0& 0\\ 0& c1& 0& 0& 0& 0\\ 0& 0& c2& 0& 0& 0\\ 0& 0& 0& c2& 0& 0\\ 0& 0& 0& 0& c3& 0\\ 0& 0& 0& 0& 0& c3\end{array}\right),$you cannot use the N-element form of c, and instead would have to use the 2N-element form. If you give c as the vector [c1;c2;c3], the software interprets it as a 3-element form, namely $\left(\begin{array}{cccccc}c1& c2& 0& 0& 0& 0\\ c2& c3& 0& 0& 0& 0\\ 0& 0& c1& c2& 0& 0\\ 0& 0& c2& c3& 0& 0\\ 0& 0& 0& 0& c1& c2\\ 0& 0& 0& 0& c2& c3\end{array}\right).$Instead, use the 2N-element form [c1;c1;c2;c2;c3;c3].

### 2N-Element Column Vector c

The software interprets a 2N-element column vector c as a diagonal matrix.

$\left(\begin{array}{ccccccccc}c\left(1\right)& 0& & 0& 0& & \cdots & 0& 0\\ 0& c\left(2\right)& & 0& 0& & \cdots & 0& 0\\ & & & & & & & & \\ 0& 0& & c\left(3\right)& 0& & \cdots & 0& 0\\ 0& 0& & 0& c\left(4\right)& & \cdots & 0& 0\\ & & & & & & & & \\ ⋮& ⋮& & ⋮& ⋮& & \ddots & ⋮& ⋮\\ 0& 0& & 0& 0& & \cdots & c\left(2N-1\right)& 0\\ 0& 0& & 0& 0& & \cdots & 0& c\left(2N\right)\end{array}\right)$

 Caution   If N = 2, the 4-element form takes precedence over the 2N-element form. For example, if your c matrix is $\left(\begin{array}{cccc}c1& 0& 0& 0\\ 0& c2& 0& 0\\ 0& 0& c3& 0\\ 0& 0& 0& c4\end{array}\right),$you cannot give c as [c1;c2;c3;c4], because the software interprets this vector as the 4-element form$\left(\begin{array}{cccc}c1& c3& 0& 0\\ c2& c4& 0& 0\\ 0& 0& c1& c3\\ 0& 0& c2& c4\end{array}\right).$Instead, use the 3N-element form [c1;0;c2;c3;0;c4] or the 4N-element form [c1;0;0;c2;c3;0;0;c4].

### 3N-Element Column Vector c

The software interprets a 3N-element column vector c as a symmetric block diagonal matrix.

$\left(\begin{array}{ccccccccc}c\left(1\right)& c\left(2\right)& & 0& 0& & \cdots & 0& 0\\ c\left(2\right)& c\left(3\right)& & 0& 0& & \cdots & 0& 0\\ & & & & & & & & \\ 0& 0& & c\left(4\right)& c\left(5\right)& & \cdots & 0& 0\\ 0& 0& & c\left(5\right)& c\left(6\right)& & \cdots & 0& 0\\ & & & & & & & & \\ ⋮& ⋮& & ⋮& ⋮& & \ddots & ⋮& ⋮\\ 0& 0& & 0& 0& & \cdots & c\left(3N-2\right)& c\left(3N-1\right)\\ 0& 0& & 0& 0& & \cdots & c\left(3N-1\right)& c\left(3N\right)\end{array}\right)$

Coefficient c(i,j,k,l) is in row (3i+k+l–4) of the vector c.

### 4N-Element Column Vector c

The software interprets a 4N-element column vector c as a block diagonal matrix.

$\left(\begin{array}{ccccccccc}c\left(1\right)& c\left(3\right)& & 0& 0& & \cdots & 0& 0\\ c\left(2\right)& c\left(4\right)& & 0& 0& & \cdots & 0& 0\\ & & & & & & & & \\ 0& 0& & c\left(5\right)& c\left(7\right)& & \cdots & 0& 0\\ 0& 0& & c\left(6\right)& c\left(8\right)& & \cdots & 0& 0\\ & & & & & & & & \\ ⋮& ⋮& & ⋮& ⋮& & \ddots & ⋮& ⋮\\ 0& 0& & 0& 0& & \cdots & c\left(4N-3\right)& c\left(4N-1\right)\\ 0& 0& & 0& 0& & \cdots & c\left(4N-2\right)& c\left(4N\right)\end{array}\right)$

Coefficient c(i,j,k,l) is in row (4i+2l+k–6) of the vector c.

### 2N(2N+1)/2-Element Column Vector c

The software interprets a 2N(2N+1)/2-element column vector c as a symmetric matrix. In the following diagram, • means the entry is symmetric.

$\left(\begin{array}{ccccccccc}c\left(1\right)& c\left(2\right)& & c\left(4\right)& c\left(6\right)& & \cdots & c\left(\left(N-1\right)\left(2N-1\right)+1\right)& c\left(\left(N-1\right)\left(2N-1\right)+3\right)\\ ·& c\left(3\right)& & c\left(5\right)& c\left(7\right)& & \cdots & c\left(\left(N-1\right)\left(2N-1\right)+2\right)& c\left(\left(N-1\right)\left(2N-1\right)+4\right)\\ & & & & & & & & \\ ·& ·& & c\left(8\right)& c\left(9\right)& & \cdots & c\left(\left(N-1\right)\left(2N-1\right)+5\right)& c\left(\left(N-1\right)\left(2N-1\right)+7\right)\\ ·& ·& & ·& c\left(10\right)& & \cdots & c\left(\left(N-1\right)\left(2N-1\right)+6\right)& c\left(\left(N-1\right)\left(2N-1\right)+8\right)\\ & & & & & & & & \\ ⋮& ⋮& & ⋮& ⋮& & \ddots & ⋮& ⋮\\ ·& ·& & ·& ·& & \cdots & c\left(N\left(2N+1\right)-2\right)& c\left(N\left(2N+1\right)-1\right)\\ ·& ·& & ·& ·& & \cdots & ·& c\left(N\left(2N+1\right)\right)\end{array}\right)$

Coefficient c(i,j,k,l), for i < j, is in row (2j2–3j+4i+2l+k–5) of the vector c. For i = j, coefficient c(i,j,k,l) is in row (2i2+i+l+k–4) of the vector c.

### 4N2-Element Column Vector c

The software interprets a 4N2-element column vector c as a matrix.

$\left(\begin{array}{ccccccccc}c\left(1\right)& c\left(3\right)& & c\left(2N+1\right)& c\left(2N+3\right)& & \cdots & c\left(2N\left(2N-1\right)+1\right)& c\left(2N\left(2N-1\right)+3\right)\\ c\left(2\right)& c\left(4\right)& & c\left(2N+2\right)& c\left(2N+4\right)& & \cdots & c\left(2N\left(2N-1\right)+2\right)& c\left(2N\left(2N-1\right)+4\right)\\ & & & & & & & & \\ c\left(5\right)& c\left(7\right)& & c\left(2N+5\right)& c\left(2N+7\right)& & \cdots & c\left(2N\left(2N-1\right)+5\right)& c\left(2N\left(2N-1\right)+7\right)\\ c\left(6\right)& c\left(8\right)& & c\left(2N+6\right)& c\left(2N+8\right)& & \cdots & c\left(2N\left(2N-1\right)+6\right)& c\left(2N\left(2N-1\right)+8\right)\\ & & & & & & & & \\ ⋮& ⋮& & ⋮& ⋮& & \ddots & ⋮& ⋮\\ c\left(2N-3\right)& c\left(2N-1\right)& & c\left(4N-3\right)& c\left(4N-1\right)& & \cdots & c\left(4{N}^{2}-3\right)& c\left(4{N}^{2}-1\right)\\ c\left(2N-2\right)& c\left(2N\right)& & c\left(4N-2\right)& c\left(4N\right)& & \cdots & c\left(4{N}^{2}-2\right)& c\left(4{N}^{2}\right)\end{array}\right)$

Coefficient c(i,j,k,l) is in row (4N(j–1)+4i+2l+k–6) of the vector c.