Vectors and Matrices

1. Building Vectors

Usual syntax to create vectors:

Feel++ Keyword

Math Object

Description

Dimension

vec(v_1,v_2,…​,v_n)

\(\begin{pmatrix} v_1\\v_2\\ \vdots \\v_n \end{pmatrix}\)

Column Vector with \(n\) rows entries being expressions

\(n \times 1\)

You can also use expressions and the unit base vectors:

Feel++ Keyword

Math Object

Description

oneX()

\(\begin{pmatrix} 1\\0\\0 \end{pmatrix}\)

Unit vector \(\overrightarrow{i}\)

oneY()

\(\begin{pmatrix} 0\\1\\0 \end{pmatrix}\)

Unit vector \(\overrightarrow{j}\)

oneZ()

\(\begin{pmatrix} 0\\0\\1 \end{pmatrix}\)

Unit vector \(\overrightarrow{k}\)

2. Building Matrices

Table 1. Matrix and vectors creation
Feel++ Keyword Math Object Description Dimension

mat<m,n>(m_11,m_12,…​,m_mn)

\(\begin{pmatrix} m_{11} & m_{12} & ...\\ m_{21} & m_{22} & ...\\ \vdots & & \end{pmatrix}\)

\(m\times n\) Matrix entries being expressions

\(m \times n\)

ones<m,n>()

\(\begin{pmatrix} 1 & 1 & ...\\ 1 & 1 & ...\\ \vdots & & \end{pmatrix}\)

\(m\times n\) Matrix Filled with 1

\(m \times n\)

zero<m,n>()

\(\begin{pmatrix} 0 & 0 & ...\\ 0 & 0 & ...\\ \vdots & & \end{pmatrix}\)

\(m\times n\) Matrix Filled with 0

\(m \times n\)

constant<m,n>(c)

\(\begin{pmatrix} c & c & ...\\ c & c & ...\\ \vdots & & \end{pmatrix}\)

\(m\times n\) Matrix Filled with a constant c

\(m \times n\)

eye<n>()

\(\begin{pmatrix} 1 & 0 & ...\\ 0 & 1 & ...\\ \vdots & & \end{pmatrix}\)

Unit diagonal Matrix of size \(n\times n\)

\(n \times n\)

Id<n>()

\(\begin{pmatrix} 1 & 0 & ...\\ 0 & 1 & ...\\ \vdots & & \end{pmatrix}\)

Unit diagonal Matrix of size \(n\times n\)

\(n \times n\)

3. Manipulating Vectors and Matrices

Let \(A\) and \(B\) be two matrices (or two vectors of the operation is defined) of dimension \(m \times n\). \(A\) and \(B\) may depend on space variables

Table 2. Matrix operations
Feel++ Keyword Math Object Description Dimension of the output

inv(A)

\(A^{-1}\)

Inverse of matrix \(A\)

\(n \times n\)

det(A)

\(\det (A)\)

Determinant of matrix \(A\)

\(1 \times 1\)

sym(A)

\(\text{Sym}(A)\)

Symmetric part of matrix \(A\): \(\frac{1}{2}(A+A^T)\)

\(n \times n\)

antisym(A)

\( \text{Asym}(A)\)

Antisymmetric part of \(A\): \(\frac{1}{2}(A-A^T)\)

\(n \times n\)

trace(A)

\(\text{tr}(A)\)

Trace of square matrix \(A\)

\(1 \times 1\)

trans(B)

\(B^T\)

Transpose of matrix \(B\) Can be used on non-squared Matrix Can be used on Vectors

\(n \times m\)

inner(A,B)

\( A \cdot B \\ A:B = \text{tr}(A*B^T)\)

Scalar product of two vectors Generalized scalar product of two matrix

\(1 \times 1\)

cross(A,B)

\( A\times B\)

Cross product of two vectors

\(n \times 1\)

eig(A)

\(\begin{pmatrix}\lambda_1 \\ \lambda_2 \\ \lambda_3\end{pmatrix}\)

vector of real \(n\) eigenvalues \(\lambda_1,\lambda_2,\lambda_3)\) of \(A\). \(A\) must be symmetric.

\(n \times 1\)

vonmises(A)

\(\begin{matrix} \text{1D:}& A_v = & A_{11}\\ \text{2D:}& A_v = & (A_{11}^2- A_{11}A_{22}+ A_{22}^2+3A_{12}^2)^{1/2} \\ \text{3D:}& A_v = & ((A_{11} - A_{22})^2 + (A_{22} - A_{33})^2 + \\ & & (A_{33} - A_{11})^2 + 6(A_{12}^2 + A_{23}^2 + A_{31}^2))^{1/2} \end{matrix}\)

if \(A\) is the Cauchy stress tensor, it computes the Von Mises yield criterion \(A_v\) (scalar value). A material starts yielding when the von Mises stress \(A_v\) reaches a value known as yield strength

\(1 \times 1\)

sum(A)

\(rr\)

S = sum(A) returns the sum of the elements of expression A along the first array dimension whose size does not equal 1.

* If A is a vectorial expression, then sum(A) returns the sum of the elements.

* If A is a matricial expression, then sum(A) returns a row vector containing the sum of each column

stem:[1 \times n]

we have \(eig(A)\)