[index]
Algebra::MatrixAlgebra / Algebra::Vector / Algebra::Covector / Algebra::SquareMatrix / Algebra::GaussianElimination
(Class of Matrices)
This class expresses matrices. For creating an actual class, use the class method ::create or the function Algebra.MatrixAlgebra(), giving the ground ring and sizes.
That has Algebra::Vector(column vectorj, Algebra::Covector(row vector), Algebra::SquareMatrix(square matrix) as subclass.
Algebra.MatrixAlgebra(ring, m, n)::create(ring, m, n)Creates the class of matrix of type (m, n) with
elements of the ring ring.
The return value of this method is a subclass of
Algebra::MatrixAlgebra.
The subclass has class methods:
ground, rsize, csize and sizes,
which returns the ground ring, the size of rows( m ),
the size of columns( n ) and the array of [m, n]
respectively.
To create the actual matrix, use the class methods: ::new, ::matrix or ::[].
::new(array)Returns the matrix of the elements designated by the array of arrays array.
Example:
M = Algebra.MatrixAlgebra(Integer, 2, 3) a = M.new([[1, 2, 3], [4, 5, 6]]) a.display #=> [1, 2, 3] #=> [4, 5, 6]
::matrix{|i, j| ... }Returns the matrix which has the i-j-th elements
evaluating ..., where i and j are the row
and the column indices
Example:
M = Algebra.MatrixAlgebra(Integer, 2, 3)
a = M.matrix{|i, j| 10*(i + 1) + j + 1}
a.display
#=> [11, 12, 13]
#=> [21, 22, 23]::[array1, array2, ..., array]Returns the matrix which has array1, array2, ..., array
as rows.
Example:
M = Algebra.MatrixAlgebra(Integer, 2, 3) a = M[[1, 2, 3], [4, 5, 6]] a.display #=> [1, 2, 3] #=> [4, 5, 6]
::collect_ij{|i, j| ... }::collect_row{|i| ... }Returns the matrix whose i-th row is the array obtained by evaluating ....
Example:
M = Algebra.MatrixAlgebra(Integer, 2, 3)
A = M.collect_row{|i| [i*10 + 11, i*10 + 12, i*10 + 13]}
A.display
#=> [11, 12, 13]
#=> [21, 22, 23]::collect_column{|j| ... }Returns the matrix whose j-th column is the array obtained by evaluating ....
Example:
M = Algebra.MatrixAlgebra(Integer, 2, 3)
A = M.collect_column{|j| [11 + j, 21 + j]}
A.display
#=> [11, 12, 13]
#=> [21, 22, 23]::*(otype)Returns the class of matrix multiplicated by otype.
Example:
M = Algebra.MatrixAlgebra(Integer, 2, 3) N = Algebra.MatrixAlgebra(Integer, 3, 4) L = M * N p L.sizes #=> [3, 4]
::vector_type::covector_type::transpose::zero[i, j](i, j)-th component.[i, j] = x(i, j)-th component with x.rsizecsizesizesrowsReturns the array of rows.
Example:
M = Algebra.MatrixAlgebra(Integer, 2, 3)
a = M.new([[1, 2, 3], [4, 5, 6]])
p a.rows #=> [[1, 2, 3], [4, 5, 6]]
p a.row(1) #=> [4, 5, 6]
a.set_row(1, [40, 50, 60])
a.display #=> [1, 2, 3]
#=> [40, 50, 60]row(i)set_row(i, array)columnsReturns the array of columns.
á:
M = Algebra.MatrixAlgebra(Integer, 2, 3)
a = M.new([[1, 2, 3], [4, 5, 6]])
p a.columns #=> [[1, 4], [2, 5], [3, 6]]
p a.column(1) #=> [2, 5]
a.set_column(1, [20, 50])
a.display #=> [1, 20, 3]
#=> [4, 50, 6]column(j)set_column(j, array)each{|row| ...}each_index{|i, j| ...} (i, j) .each_i{|i| ...}i of rows.each_j{|j| ...}j of columns.each_row{|r| ... }each_column{|c| ... }matrix{|i, j| ... }collect_ij{|i, j| ... }collect_row{|i| ... }collect_column{|j| ... }minor(i, j)cofactor(i, j)minor(i, j) ** (i + j).cofactor_matrixself.class.transpose.matrix{|i, j| cofactor(j, i)}.adjoint==(other)+(other)-(other)*(other)Returns the product of self and other.
Example:
M = Algebra.MatrixAlgebra(Integer, 2, 3)
N = Algebra.MatrixAlgebra(Integer, 3, 4)
L = M * N
a = M[[1, 2, 3], [4, 5, 6]]
b = N[[-3, -2, -1, 0], [1, 2, 3, 4], [5, 6, 7, 8]]
c = a * b
p c.type #=> L
c.display #=> [14, 20, 26, 32]
#=> [23, 38, 53, 68]**(n)/(other)rankdsum(other)Returns the direct sum of self and other.
Example:
a = Algebra.MatrixAlgebra(Integer, 2, 3)[
[1, 2, 3],
[4, 5, 6]
]
b = Algebra.MatrixAlgebra(Integer, 3, 2)[
[-1, -2],
[-3, -4],
[-5, -6]
]
(a.dsum b).display #=> 1, 2, 3, 0, 0
#=> 4, 5, 6, 0, 0
#=> 0, 0, 0, -1, -2
#=> 0, 0, 0, -3, -4
#=> 0, 0, 0, -5, -6to_aryflattendiagconvert_to(ring)Returns the conversion of self to ring's object.
Example:
require "matrix-algebra"
require "residue-class-ring"
Z3 = Algebra.ResidueClassRing(Integer, 3)
a = Algebra.MatrixAlgebra(Integer, 2, 3)[
[1, 2, 3],
[4, 5, 6]
]
a.convert_to(Algebra.MatrixAlgebra(Z3, 2, 3)).display
#=> 1, 2, 0
#=> 1, 2, 0transposeReturns the transposed matrix.
Example:
M = Algebra.MatrixAlgebra(Integer, 2, 3)
a = M.new([[1, 2, 3], [4, 5, 6]])
Mt = M.transpose
b = a.transpose
p b.type #=> Mt
b.display #=> [1, 4]
#=> [2, 5]
#=> [3, 6]dupReturns the duplication of self.
Example:
M = Algebra.MatrixAlgebra(Integer, 2, 3)
a = M.new([[1, 2, 3], [4, 5, 6]])
b = a.dup
b[1, 1] = 50
a.display #=> [1, 2, 3]
#=> [4, 5, 6]
b.display #=> [1, 2, 3]
#=> [4, 50, 6]display([out])(Class of Vector)
The class of column vectors.
none.
Algebra.Vector(ring, n)Algebra::Vector.create(ring, n)Creates the class of the n-th dimensional (column) vector over the ring.
The return value of this is a subclass of Algebra::Vector. This subclass has the class methods: ground and size, which returns ring and the size n respectively.
To get actual vectors, use the class methods: new, matrix or [].
Algebra::Vector is identified with
Algebra::MatrixAlgebra of type [n, 1].
Algebra::Vector::new(array)Returns the vector of the array.
Example:
V = Algebra.Vector(Integer, 3) a = V.new([1, 2, 3]) a.display #=> [1] #=> [2] #=> [3]
Algebra::Vector::vector{|i| ... }Returns the vector of ... as the i-th element.
Example:
V = Algebra.Vector(Integer, 3)
a = V.vector{|j| j + 1}
a.display
#=> [1]
#=> [2]
#=> [3]Algebra::Vector::matrix{|i, j| ... }sizeto_atransposeinner_product(other)inner_product_complex(other)inner_product(other.conjugate).norm2inner_product(self).norm2_complexinner_product(self.conjugate).(Row Vector Class)
The class of row vectors.
none.
Algebra.Covector(ring, n)Algebra::Covector::create(ring, n)Creates the class of the n-th dimensional (row) vector over the ring.
The return value of this is a subclass of Algebra::MatrixAlgebra::CoVector. This subclass has the class methods: ground and size, whic h returns ring and the size n respectively.
To get actual vectors, use the class methods: new, matrix or [].
Algebra::Covector is identified with
[1, n]-type
Algebra::MatrixAlgebra.
Algebra::Covector::new(array)Returns the row vector of the array.
Example:
V = Algebra::Covector(Integer, 3) a = V.new([1, 2, 3]) a.display #=> [1, 2, 3]
Algebra::Covector::covector{|j| ... }Returns the vector of ... as the j-th element.
Example:
V = Algebra.Covector(Integer, 3)
a = V.covector{|j| j + 1}
a.display
#=> [1, 2, 3]Algebra::Covector::matrix{|i, j| ... }sizeto_atransposeinner_product(other)inner_product_complex(other)inner_product(other.conjugate).norm2inner_product(self).norm2_complexinner_product(self.conjugate).(Class of SquareMatrix)
The Ring of Square Matrices over a ring.
none.
Algebra.SquareMatrix(ring, size)Algebra::SquareMatrix::create(ring, n)Creates the class of square matrices.
The return value of this is the subclass of Algebra::SquareMatrix. This subclass has the class methods ground and size which returns ring and the size n respectively.
Algebra::SquareMatrix is identified
with Algebra::MatrixAlgebra::MatrixAlgebra of type
[n, n].
To get the actual matrices, use the class methods Algebra::SquareMatrix::new, Algebra::SquareMatrix::matrix or Algebra::SquareMatrix::[].
Algebra::SquareMatrix.determinant(aa)Algebra::SquareMatrix.det(aa)Algebra::SquareMatrix::unityAlgebra::SquareMatrix::zeroAlgebra::SquareMatrix::const(x)sizeconst(x)determinantinverse/(other)self * other.inverse. If other is a schalar,
divides each entries by other.char_polynomial(ring)char_matrix(ring)_char_matrix(poly_ring_matrix)(Module of Gaussian Elimination)
Module of the elimination method of Gauss.
gaussian-elimination.rb
none.
none.
swap_r!(i, j)swap_r(i, j)swap_c!(i, j)swap_c(i, j)multiply_r!(i, c)multiply_r(i, c)multiply_c!(j, c)multiply_c(j, c)divide_r!(i, c)divide_r(i, c)divide_c!(j, c)divide_c(j, c)mix_r!(i, j, c)mix_r(i, j, c)mix_c!(i, j, c)mix_c(i, j, c)left_eliminate!Transform to the step matrix by the left fundamental transformation.
The return value is the array of the square matrix which used to transform, its determinant and the rank.
Example:
require "matrix-algebra"
require "mathn"
class Rational < Numeric
def inspect; to_s; end
end
M = Algebra.MatrixAlgebra(Rational, 4, 3)
a = M.matrix{|i, j| i*10 + j}
b = a.dup
c, d, e = b.left_eliminate!
b.display #=> [1, 0, -1]
#=> [0, 1, 2]
#=> [0, 0, 0]
#=> [0, 0, 0]
c.display #=> [-11/10, 1/10, 0, 0]
#=> [1, 0, 0, 0]
#=> [1, -2, 1, 0]
#=> [2, -3, 0, 1]
p c*a == b#=> true
p d #=> 1/10
p e #=> 2left_inverseleft_sweepstep_matrix?kernel_basisReturns the array of vector( Algebra::Vector ) such that the right multiplication of it is null.
Example:
require "matrix-algebra"
require "mathn"
M = Algebra.MatrixAlgebra(Rational, 5, 4)
a = M.matrix{|i, j| i + j}
a.display #=>
#[0, 1, 2, 3]
#[1, 2, 3, 4]
#[2, 3, 4, 5]
#[3, 4, 5, 6]
#[4, 5, 6, 7]
a.kernel_basis.each do |v|
puts "a * #{v} = #{a * v}"
#=> a * [1, -2, 1, 0] = [0, 0, 0, 0, 0]
#=> a * [2, -3, 0, 1] = [0, 0, 0, 0, 0]
enddeterminant_by_elimination