Expression syntax

Matrices are defined separate from their usage. See Defining matrices.

It’s easier to talk about how to combine these pre-defined matrices into expressions first, and then talk about anonymous matrices.

Composition

The expression input box and expression definition dialog allow you to compose matrices using multiplication (scalar and matrix), addition, exponentiation, brackets, and transposes. Obviously you can’t easily type something like \(\left(2\mathbf{A}^{2}3\mathbf{B}^{T}\right)^{-1}\mathbf{C}\), so lintrans uses a more keyboard-friendly syntax.

For this example, you would type (2A^{2} 3B^{T})^{-1} C or (2A^{2}3B^T)^-1C if you wanted to be more concise. Notice that the squared part of \(\mathbf{A}^{2}\) didn’t lose its braces. This is because lintrans ignores spaces and parses exponents “greedily” 1, meaning that A^2 3B will be interpreted as A^{23}B, not A^{2}3B as probably intended. If you have two numbers next to each other like this, use braces (A^{2}3B) or brackets ((A^2)(3B)) to separate the terms.

Most of the rules are exactly what you expect:

  • A single matrix is written as a capital letter like A or B

  • To multiply a matrix by a scalar, you can just write it in front, like 3A or -1.568237M

  • \(\mathbf{AB}\) is written as AB

  • \(\mathbf{A} + \mathbf{B}\) is written as A+B

  • \(\mathbf{A} - \mathbf{B}\) is written as A-B

  • \(\mathbf{A}^{n}\) is written as A^n or A^{n}, where n is a positive or negative integer

  • \(\mathbf{A}^{T}\) is written as A^T or A^{T}

Additionally, a matrix term may be replaced by rot(x) to signify an anticlockwise rotation by \(x\) degrees. rot(x) is equivalent to the standard rotation matrix \(\begin{pmatrix}\cos x & -\sin x\\ \sin x & \cos x\end{pmatrix}\). This rotation function can be used anywhere that a defined matrix could be used.

A matrix term may also be replaced by a parenthesised sub-expression. If you’ve visualized the transformation AB and now want to visualize three times its inverse, you could define a new matrix C equal to AB and visualize 3C^-1, or you could directly visualize 3(AB)^-1. These sub-expressions may contain any valid expression (even nested sub-expressions) and can be used anywhere that a defined matrix could be used.

Examples

Note

In this textbook format, I’m using \(\mathbf{R}_{\theta}\) to represent an anticlockwise rotation of \(\theta^{\circ}\). I’m also using spaces for clarity in the lintrans format, but these spaces are ignored by the program. Use braces to clarify ambiguous expressions.

Textbook format

lintrans format

\(\mathbf{A}^{2}\ 3\mathbf{B}\)

A^{2}3B

\(\mathbf{A}^{23}\ \mathbf{B}\)

A^23B

\(\left(2\mathbf{A}^{T} - 3\mathbf{B}^{2}\ \mathbf{C}\right)^{-1}\)

(2A^T - 3B^2 C)^-1

\(\mathbf{M}\ \left(\mathbf{A}^{2}\ \mathbf{R}_{45}\right)^{-1}\ \mathbf{X}\)

M (A^2 rot(45))^-1 X

\(\mathbf{A}\ \left(-2.5\mathbf{B}^{2}\ \left(\mathbf{C}^{-1}\ 2\mathbf{R}_{90}\ \mathbf{D}\right)^{-1}\right)^{3}\)

A (-2.5B^2 (C^{-1} 2rot(90) D)^-1)^3

I recommend to always put exponents in braces. I haven’t done it here, just to show when it’s technically necessary, but it makes things easier to read, so it’s good practice to use it all the time.

Anonymous matrices

It is often useful to use a simple numerically defined matrix once or twice as part of an example, but it can be a hassle to define a matrix and then only use it once or twice.

To fix this problem, you can use anonymous matrices. Anonymous matrices are those which don’t have a name. If you’ve used MATLAB or GNU Octave before, then the syntax should seem familiar.

A matrix of the form \(\begin{pmatrix}a & b\\ c & d\end{pmatrix}\) would be represented as [a b; c d]. The spaces are necessary.

An anonymous matrix can be used anywhere in an expression that a pre-defined matrix can. For example, in Defining matrices, we defined \(\mathbf{A}\) as being \(\begin{pmatrix}2 & -3.2\\ -1.9 & 0.63\end{pmatrix}\). If we only wanted this matrix once, then instead of using something like 4A^2 in an expression, we could use 4[2 -3.2; -1.9 0.63]^2.

Footnotes

1

The parser will see the character ^ and keep reading numbers after it (or a possible - at the start), until it reaches a character that it is not a number. It will then take all the numbers it’s seen and call that the exponent. If there are braces after the ^, then it will just use the number in the braces.