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 : Iterator(T)
Returns an iterator that enumerates through the elements of the main diagonal.
-
#inv
Computes the inverse of this matrix.
-
#inverse
Computes the inverse of this matrix.
-
#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 inverse of this matrix.
This method can only be called on square matrices. Returns nil if there is no inverse.
matrix = Matrix[[1.0, 4.0, 7.0], [5.0, 8.0, 2.0], [9.0, 3.0, 6.0]]
matrix.inverse # => [
# [-0.103703704, 0.007407407, 0.118518519],
# [0.02962963, 0.140740741, −0.081481481],
# [0.140740741, −0.081481481, 0.02962963]
# ]
matrix = Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
matrix.inverse # => nil
Computes the inverse of this matrix.
This method can only be called on square matrices. Returns nil if there is no inverse.
matrix = Matrix[[1.0, 4.0, 7.0], [5.0, 8.0, 2.0], [9.0, 3.0, 6.0]]
matrix.inverse # => [
# [-0.103703704, 0.007407407, 0.118518519],
# [0.02962963, 0.140740741, −0.081481481],
# [0.140740741, −0.081481481, 0.02962963]
# ]
matrix = Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
matrix.inverse # => nil
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