Binary operators
next -
skip -
up -
start
The package supports binary operations
X = A + B; // matrix addition
X = A - B; // matrix subtraction
X = A * B; // matrix multiplication
X = A.i() * B; // equation solve (square matrix A)
X = A | B; // concatenate horizontally (concatenate the rows)
X = A & B; // concatenate vertically (concatenate the columns)
X = SP(A, B); // elementwise product of A and B (Schur product)
bool b = A == B; // test whether A and B are equal
bool b = A != B; // ! (A == B)
A += B; // A = A + B;
A -= B; // A = A - B;
A *= B; // A = A * B;
A |= B; // A = A | B;
A &= B; // A = A & B;
<, >, <=, >= // included for compatibility with STL - see notes
Notes:
- If you are doing repeated multiplication. For example A*B*C, use
brackets to force the order of evaluation to minimise the number of
operations. If C is a column vector and A is not a vector,
then it will usually reduce the number of operations to use A*(B*C).
- In the equation solve example case the inverse is not explicitly
calculated. An LU decomposition of A is performed and this is
applied to B. This is more efficient than calculating the inverse and
then multiplying.
See also multiple matrix solving.
- The package does not (yet?) recognise B*A.i() as an equation
solve and the inverse of A would be calculated.
It is probably better to use (A.t().i()*B.t()).t().
- Horizontal or vertical concatenation returns a result of type Matrix,
RowVector or ColumnVector.
- If A is m x p, B is m x q, then A | B is m x
(p+q) with the k-th row being the elements of the k-th row of A
followed by the elements of the k-th row of B.
- If A is p x n, B is q x n, then A & B is (p+q)
x n with the k-th column being the elements of the k-th column of A
followed by the elements of the k-th column of B.
- For complicated concatenations of matrices, consider instead using
submatrices.
- See the section on submatrices on
using a submatrix on the RHS of an expression.
- Two matrices are equal if their difference is zero. They may be of
different types. For the CroutMatrix or BandLUMatrix they must be of the
same type and have all their elements equal. This is not a very useful
operator and is included for compatibility with some container templates.
- The inequality operators are included for compatibility with the
standard template library. If actually called, they will throw an exception. So don't
try to sort a list of matrices.
next -
skip -
up -
start