|
consteig
Compile-time eigenvalue and eigenvector computation for C++17
|
Fixed-size matrix type and arithmetic operations. More...
Classes | |
| class | consteig::Matrix< T, R, C > |
| Fixed-size matrix with compile-time dimensions. More... | |
Functions | |
| template<typename T , Size R, Size C> | |
| constexpr Matrix< T, C, R > | consteig::transpose (const Matrix< T, R, C > &mat) |
| Matrix transpose. | |
| template<typename T , Size R, Size C> | |
| constexpr T | consteig::trace (const Matrix< T, R, C > &mat) |
| Trace: sum of diagonal elements. | |
| template<typename T , Size R, Size C> | |
| constexpr T | consteig::determinant (const Matrix< T, R, C > &mat) |
| Determinant via Laplace (cofactor) expansion. | |
| template<typename T , Size R, Size C> | |
| constexpr T | consteig::norm (const Matrix< T, R, C > &mat) |
Frobenius (Euclidean) norm: sqrt(sum of squared elements). | |
| template<typename T , Size R, Size C> | |
| constexpr T | consteig::dot (const Matrix< T, R, C > &lhs, const Matrix< T, R, C > &rhs) |
| Dot product of two 1×N row vectors. | |
| template<typename T , Size R, Size C, typename... Args> | |
| constexpr Matrix< T, R, C > | consteig::make_matrix (Args... args) |
| Construct a Matrix from a flat list of scalar arguments in row-major order. | |
| template<typename To , typename From , Size R, Size C> | |
| constexpr Matrix< To, R, C > | consteig::matrix_cast (const Matrix< From, R, C > &src) |
| Convert a matrix from one element type to another. | |
| template<typename T , Size R, Size C> | |
| constexpr Matrix< T, R, C > | consteig::operator+ (const Matrix< T, R, C > &lhs, const Matrix< T, R, C > &rhs) |
| Element-wise matrix addition. | |
| template<typename T , Size R, Size C> | |
| constexpr Matrix< T, R, C > | consteig::operator- (const Matrix< T, R, C > &lhs, const Matrix< T, R, C > &rhs) |
| Element-wise matrix subtraction. | |
| template<typename T , Size R1, Size C1, Size R2, Size C2> | |
| constexpr Matrix< T, R1, C2 > | consteig::operator* (const Matrix< T, R1, C1 > &lhs, const Matrix< T, R2, C2 > &rhs) |
| Matrix multiplication: (R1×C1) * (R2×C2) → (R1×C2). | |
| template<typename T , Size R, Size C> | |
| constexpr Matrix< T, R, C > | consteig::operator* (const T &lhs, const Matrix< T, R, C > &rhs) |
| Scalar-matrix multiplication. | |
| template<typename T , Size S> | |
| constexpr Matrix< T, S, S > | consteig::diagonal (const T val) |
Create an S×S matrix with val on the main diagonal and zeros elsewhere. | |
| template<typename T , Size S> | |
| constexpr Matrix< T, S, S > | consteig::eye () |
| Create an S×S identity matrix. | |
| template<typename T , Size R, Size C> | |
| constexpr T | consteig::norm1 (const Matrix< T, R, C > &mat) |
| 1-norm (maximum absolute column sum). | |
| template<typename T , Size R, Size C> | |
| constexpr T | consteig::normInf (const Matrix< T, R, C > &mat) |
| Infinity-norm (maximum absolute row sum). | |
| template<typename T , Size R, Size C> | |
| constexpr Matrix< T, R, C > | consteig::sqrt (const Matrix< T, R, C > &mat) |
| Element-wise square root. | |
| template<typename T , Size N> | |
| constexpr Matrix< T, N+1u, 1u > | consteig::char_poly (const Matrix< T, N, N > &A) |
| Monic characteristic polynomial via the Faddeev-LeVerrier algorithm. | |
| template<typename T , Size R, Size C> | |
| constexpr bool | consteig::equalWithinMat (const Matrix< T, R, C > &a, const Matrix< T, R, C > &b, const T thresh) |
| Element-wise approximate equality within an absolute tolerance. | |
Fixed-size matrix type and arithmetic operations.
Matrix transpose.
| T | Scalar element type. |
| R | Number of rows in input (= columns in output). |
| C | Number of columns in input (= rows in output). |
| mat | Input matrix. |
Trace: sum of diagonal elements.
| T | Scalar type. |
| R | Number of rows (must equal C). |
| C | Number of columns. |
| mat | Square input matrix. |
mat(i,i) for all i. R == C (enforced by static_assert). Determinant via Laplace (cofactor) expansion.
Computes the determinant recursively. Time complexity is O(n!), so this is only practical for small matrices (n ≤ 4 or 5). Used internally by checkEigenValues only when R <= 4.
| T | Scalar type. |
| R | Number of rows (must equal C). |
| C | Number of columns. |
| mat | Square input matrix. |
mat. R == C (enforced by static_assert). Frobenius (Euclidean) norm: sqrt(sum of squared elements).
| T | Floating-point scalar type. |
| R | Number of rows. |
| C | Number of columns. |
| mat | Input matrix. |
|
constexpr |
Dot product of two 1×N row vectors.
Computes lhs * rhs^T and returns the scalar result.
| T | Scalar element type. |
| R | Must be 1 (enforced by static_assert). |
| C | Number of elements. |
| lhs | First row vector (1×C). |
| rhs | Second row vector (1×C). |
Construct a Matrix from a flat list of scalar arguments in row-major order.
Alternative to aggregate initialization when nested braces are inconvenient. Arguments are filled row by row, left to right, identical to how values appear when written out as a matrix on paper.
| T | Scalar element type. |
| R | Number of rows (compile-time). |
| C | Number of columns (compile-time). |
| Args | Deduced scalar argument types; must all be convertible to T. |
The number of arguments must equal R * C exactly (enforced by static_assert).
Convert a matrix from one element type to another.
Performs an element-wise static_cast<To> on each element. This is the preferred way to change element type (e.g. double to float) since Matrix has no converting constructor in order to preserve aggregate initialization.
| To | Target element type. |
| From | Source element type. |
| R | Number of rows (compile-time). |
| C | Number of columns (compile-time). |
| src | Input matrix with element type From. |
To and the same dimensions.
|
constexpr |
Element-wise matrix addition.
| T | Scalar element type. |
| R | Number of rows. |
| C | Number of columns. |
| lhs | Left-hand operand. |
| rhs | Right-hand operand. |
lhs(i,j) + rhs(i,j).
|
constexpr |
Element-wise matrix subtraction.
| T | Scalar element type. |
| R | Number of rows. |
| C | Number of columns. |
| lhs | Left-hand operand. |
| rhs | Right-hand operand. |
lhs(i,j) - rhs(i,j).
|
constexpr |
Matrix multiplication: (R1×C1) * (R2×C2) → (R1×C2).
| T | Scalar element type. |
| R1 | Rows of lhs. |
| C1 | Columns of lhs (must equal R2). |
| R2 | Rows of rhs (must equal C1). |
| C2 | Columns of rhs. |
| lhs | Left matrix. |
| rhs | Right matrix. |
C1 == R2 (enforced by static_assert).
|
constexpr |
Scalar-matrix multiplication.
| T | Scalar and element type. |
| R | Number of rows. |
| C | Number of columns. |
| lhs | Scalar multiplier. |
| rhs | Matrix to scale. |
lhs * rhs(i,j). Create an S×S matrix with val on the main diagonal and zeros elsewhere.
| T | Scalar type. |
| S | Matrix dimension. |
| val | Value to place on the diagonal. |
Create an S×S identity matrix.
| T | Scalar type. |
| S | Matrix dimension. |
1-norm (maximum absolute column sum).
| T | Scalar type. |
| R | Number of rows. |
| C | Number of columns. |
| mat | Input matrix. |
Infinity-norm (maximum absolute row sum).
| T | Scalar type. |
| R | Number of rows. |
| C | Number of columns. |
| mat | Input matrix. |
Element-wise square root.
Applies sqrt to every element. Each element must be non-negative; a negative element triggers a compile-time error.
| T | Floating-point scalar type. |
| R | Number of rows. |
| C | Number of columns. |
| mat | Input matrix. |
result(i,j) = sqrt(mat(i,j)). Monic characteristic polynomial via the Faddeev-LeVerrier algorithm.
Computes det(lam*I - A) = lam^N + c_1*lam^(N-1) + ... + c_N using only matrix multiplications and traces; no eigenvalues, no complex arithmetic. Susceptible to catastrophic cancellation for near-repeated eigenvalues.
| T | Scalar type. |
| N | Matrix dimension. |
| A | Square NxN matrix. |
|
constexpr |
Element-wise approximate equality within an absolute tolerance.
Returns true if every element satisfies |a(i,j) - b(i,j)| < thresh. Prefer this over operator== for floating-point matrices. Can also be called as a member function via Matrix::equalWithin.
| T | Scalar element type. |
| R | Number of rows. |
| C | Number of columns. |
| a | First matrix. |
| b | Second matrix. |
| thresh | Absolute per-element tolerance. |
true if all elements are within thresh of each other.