module Geode::SquareMatrix(T, M, N)
Overview
Operations applicable to square matrices.
Intended to be used as a mix-in on matrix types. M and N are positive integers indicating the number of rows and columns respectively. These methods will produce a compilation error when called on a non-square matrix.
Direct including types
- Geode::Matrix(T, M, N)
- Geode::Matrix1x1(T)
- Geode::Matrix2x2(T)
- Geode::Matrix3x3(T)
- Geode::Matrix4x4(T)
Defined in:
geode/matrices/square.crInstance Method Summary
-
#determinant
Computes the determinant of this matrix.
-
#diagonal : CommonVector(T, N)
Retrieves the elements of the main diagonal.
-
#each_diagonal(& : T -> _) : Nil
Enumerates through the elements of the main diagonal.
-
#each_diagonal
Returns an iterator that enumerates through the elements of the main diagonal.
-
#trace
Computes the trace of the matrix.
Instance Method Detail
Computes the determinant of this matrix.
This method can only be called on square matrices.
matrix = Matrix[[1, 4, 7], [5, 8, 2], [9, 3, 6]]
matrix.determinant # => -405
Retrieves the elements of the main diagonal.
Returns the elements as a vector.
This method can only be called on square matrices.
matrix = Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
matrix.diagonal # => (1, 5, 9)
Enumerates through the elements of the main diagonal.
This method can only be called on square matrices.
matrix = Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
matrix.each_diagonal do |e|
puts e
end
# Output:
# 1
# 5
# 9
Returns an iterator that enumerates through the elements of the main diagonal.
This method can only be called on square matrices.
matrix = Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
matrix.each_diagonal.to_a # => [1, 5, 9]
Computes the trace of the matrix.
The trace is the sum of the elements along the main diagonal.
This method can only be called on square matrices.
matrix = Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
matrix.trace # => 15