
[index-ja] Algebra::MatrixAlgebra / Algebra::Vector / Algebra::Covector /
Algebra::SquareMatrix / Algebra::GaussianElimination

Algebra::MatrixAlgebra

(󥯥饹)

ɽޤºݤΥ饹ˤϴĤȥꤷơ饹
å ::create 뤤ϴؿ Algebra::MatrixAlgebra() Ѥޤ

֥饹Ȥ Algebra::Vector(ĥ٥ȥ, Algebra::Covector(٥ȥ),
Algebra::SquareMatrix() ޤ

ե̾:

  matrix-algebra.rb

ѡ饹:

  Object

󥯥롼ɤƤ⥸塼:

  Algebra::GaussianElimination

Ϣؿ:

Algebra.MatrixAlgebra(ring, m, n)
    ::create(ring, m, n)ƱǤ
   

饹᥽å:

::create(ring, m, n)
     ring ǤȤ, (m, n) ιɽ륯饹ޤ
   
    Υ᥽åɤͤ Algebra::MatrixAlgebra 饹Υ֥饹Ǥ
    ֥饹ˤϥ饹᥽åɤȤ ground  rsize, csize, sizes 
    줾졢Ȥʤ ringԤΥ mΥ n [m,
    n] ֤ޤ
   
    ºݤ˹ˤ ::new, ::matrix, ::[] Ȥޤ
   
::new(array)
    array ȤȤǤȤ֤ޤ
   
    :
    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| ... }
    i  j ˹ԤΥǥåͿ ... ɾͤ (i, j) ʬˤ
    ֤ޤ
   
    :
    M = Alebra.MatrixAlgebra(Integer, 2, 3)
    a = M.matrix{|i, j| 10*(i + 1) + j + 1}
    a.display
      #=> [11, 12, 13]
      #=> [21, 22, 23]
   
::[array1, array2, ..., arrayr]
     array1, array2, ..., arrayr 򤽤줾ԤȤ֤ޤ
   
    :
    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| ... }
    ::matrix ˤ褯Ƥޤ֤ͤ Algebra::MatrixAlgebra Ǥʤ2
    (Array  Array)Ǥ
   
::collect_row{|i| ... }
     i Ԥ ... ɾ¤٤֤ޤ
   
    :
    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| ... }
     j  ... ɾ¤٤֤ޤ
   
    :
    M = Algebra.MatrixAlgebra(Integer, 2, 3)
    A = M.collect_column{|j| [11 + j, 21 + j]}
    A.display
      #=> [11, 12, 13]
      #=> [21, 22, 23]
   
::*(otype)
    2Ĥιηݤ饹֤ޤ
   
    :
    M = Algebra.MatrixAlgebra(Integer, 2, 3)
    N = Algebra.MatrixAlgebra(Integer, 3, 4)
    L = M * N
    p L.sizes #=> [3, 4]
   
::vector
    rsize Ʊνĥ٥ȥ(Vector)饹֤ޤ
   
::covector
    csize Ʊβ٥ȥ(CoVector)饹֤ޤ
   
::transpose
    ž֤Ԥä󥯥饹֤ޤ
   
::zero
    ֤ޤ
   

᥽å:

[i, j]
    (i, j) ʬ֤ޤ
   
[i, j] = x
    (i, j) ʬ x ˤޤ
   
rsize
    ԥ֤ޤ::rsize ƱǤ
   
csize
    󥵥֤ޤ::csize ƱǤ
   
sizes
    [rsize, csize] ֤ޤ ::sizes ƱǤ
   
rows
    ƹԤǤȤ֤ޤ
   
    :
    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)
    i ܤȤ֤ޤ
   
set_row(i, array)
    i ܤ array 촹ޤ
   
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)
    j ܤȤ֤ޤ
   
set_column(j, array)
    j ܤ array 촹ޤ
   
each{|row| ...}
    ƹԤˤ row 륤ƥ졼Ǥ
   
each_index{|i, j| ...}
    ź (i, j) ˴ؤ륤ƥ졼Ǥ
   
each_i{|i| ...}
    ƹԤź i ˴ؤ륤ƥ졼Ǥ
   
each_j{|j| ...}
    ź j ˴ؤ륤ƥ졼Ǥ
   
each_row{|r| ... }
    ƹԤˤ r 륤ƥ졼Ǥ each ƱǤ
   
each_column{|c| ... }
    ˤ c 륤ƥ졼Ǥ
   
matrix{|i, j| ... }
    ::matrix ƱǤ
   
collect_ij{|i, j| ... }
    ::collect_ij ƱǤ
   
collect_row{|i| ... }
    ::collect_row ƱǤ
   
collect_column{|j| ... }
    ::collect_column ƱǤ
   
==(other)
    Ȥ֤ޤ
   
+(other)
    ¤׻ޤ
   
-(other)
    ׻ޤ
   
*(other)
    Ѥ׻ޤ
   
    :
    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)
    n ׻ޤ
   
/(other)
    ׻ޤ
   
dsum(other)
    ľ¤֤ޤ
   
    :
    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,  -6
   
convert_to(ring)
    self γʬ ring ˥СȤޤ
   
    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,   0
   
diag
    гʬ֤ޤ
   
transpose
    žֹ֤ޤ
   
    :
    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]
   
dup
    ʣޤ
   
    :
    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])
     out ɽޤout ά $stdout ɽޤ
   

Algebra::Vector

(ĥ٥ȥ륯饹)

٥ȥΥ饹Ǥ

ѡ饹:

  Algebra::MatrixAlgebra

󥯥롼ɤƤ⥸塼:

ʤ

Ϣؿ:

Algebra.Vector(ring, n)
    Algebra::Vector::create(ring, n) ƱǤ
   

饹᥽å:

Algebra::Vector::create(ring, n)
     ring ǤȤ, n Υ٥ȥʽĥ٥ȥɽ륯饹
    ޤ
   
    Υ᥽åɤͤ Algebra::Vector 饹Υ֥饹ǤΥ֥
    ˤϥ饹᥽åɤȤ ground  size 졢줾졢Ȥʤ
     ring n ֤ޤ
   
    ºݤ˥٥ȥˤϥ饹᥽å new, matrix, [] Ȥޤ
   
    Algebra::Vector  n  1  Algebra::MatrixAlgebra Ʊ뤵ޤ
   
Algebra::Vector::new(array)
    array ȤȤǤȤĥ٥ȥ֤ޤ
   
    :
    V = Algebra.Vector(Integer, 3)
    a = V.new([1, 2, 3])
    a.display
      #=> [1]
      #=> [2]
      #=> [3]
   
Algebra::Vector::vector{|i| ... }
     i ʬ ... ˤ٥ȥ֤ޤ
   
    :
    V = Algebra.Vector(Integer, 3)
    a = V.vector{|j| j + 1}
    a.display
      #=> [1]
      #=> [2]
      #=> [3]
   
Algebra::Vector::matrix{|i, j| ... }
     i ʬ ... ˤ٥ȥ֤ޤ j ˤϾ 0 ޤ
   

᥽å:

size
    ֤ޤ
   
to_a
    ʬˤ֤ޤ
   
transpose
    ٥ȥ Algebra::Covector ž֤ޤ
   

Algebra::Covector

(٥ȥ륯饹)

٥ȥΥ饹Ǥ

ѡ饹:

  Algebra::MatrixAlgebra

󥯥롼ɤƤ⥸塼:

ʤ

Ϣؿ:

Algebra.Covector(ring, n)
    Algebra::Covector::create (ring n)ƱǤ
   

饹᥽å:

Algebra::Covector::create(ring, n)
     ring ǤȤ, n Υ٥ȥʲ٥ȥɽ륯饹
    ޤ
   
    Υ᥽åɤͤ Algebra::Covector 饹Υ֥饹ǤΥ֥
    饹ˤϥ饹᥽åɤȤ ground  size 졢줾졢Ȥ
     ring n ֤ޤ
   
    ºݤ˥٥ȥˤϥ饹᥽å new, matrix, [] Ȥޤ
   
    Algebra::Covector  1  n  Algebra::MatrixAlgebra Ʊ뤵ޤ
   
Algebra::Covector::new(array)
    array ȤȤǤȤ벣٥ȥ֤ޤ
   
    :
    V = Algebra.Covector(Integer, 3)
    a = V.new([1, 2, 3])
    a.display
      #=> [1, 2, 3]
   
Algebra::Covector::covector{|j| ... }
     j ʬ ... ˤ٥ȥ֤ޤ
   
    :
    V = Algebra.Covector(Integer, 3)
    a = V.covector{|j| j + 1}
    a.display
      #=> [1, 2, 3]
   
Algebra::Covector::matrix{|i, j| ... }
     j ʬ ... ˤ٥ȥ֤ޤi ˤϾ 0 ޤ
   

᥽å:

size
    ֤ޤ
   
to_a
    ʬˤ֤ޤ
   
transpose
    ٥ȥ Algebra::Vector ž֤ޤ
   

Algebra::SquareMatrix

(ĥ饹)

κĤɽ륯饹Ǥ

ѡ饹:

  Algebra::MatrixAlgebra

󥯥롼ɤƤ⥸塼:

ʤ

Ϣؿ:

Algebra.SquareMatrix(ring, size)
    Algebra::SquareMatrix::create(ring, n) ƱǤ
   

饹᥽å:

Algebra::SquareMatrix::create(ring, n)
    ɽ륯饹ޤ
   
    Υ᥽åɤͤ Algebra::SquareMatrix 饹Υ֥饹ǤΥ
    ֥饹ˤϥ饹᥽åɤȤ ground  size 졢줾졢
    Ȥʤ ring n ֤ޤ
   
    SquareMatrix  n  n  Algebra::MatrixAlgebra Ʊ뤵ޤ
   
    ºݤ˹ˤϥ饹᥽å new, matrix, [] Ȥޤ
   
Algebra::SquareMatrix::unity
    ñ̹֤ޤ
   
Algebra::SquareMatrix::zero
    ֤ޤ
   
Algebra::SquareMatrix.const(x)
    ʬ x Υ顼֤ޤ
   

᥽å

size
    ֤ޤ
   
const(x)
    ʬ x Υ顼֤ޤ
   
determinant
    󼰤֤ޤ
   
char_polynomial(ring)
    ring ¿༰ĤͿȡ¿༰֤ޤ
   

Algebra::GaussianElimination

(ξõˡ⥸塼)

ݤФˡ¸⥸塼Ǥ

ե̾:

gaussian-elimination.rb

󥯥롼ɤƤ⥸塼:

ʤ

饹᥽å:

ʤ

᥽å

swap_r!(i, j)
    i Ԥ j Ԥ촹ޤ
   
swap_r(i, j)
    i Ԥ j Ԥ촹Τ֤ޤ
   
swap_c!(i, j)
    i  j 촹ޤ
   
swap_c(i, j)
    i  j 촹Τ֤ޤ
   
multiply_r!(i, c)
    i ܤ c ܤޤ
   
multiply_r(i, c)
    i ܤ c ܤΤ֤ޤ
   
multiply_c!(j, c)
    j ܤ c ܤޤ
   
multiply_c(j, c)
    j ܤ c ܤΤ֤ޤ
   
divide_r!(i, c)
    i ܤ c ǳޤ
   
divide_r(i, c)
    i ܤ c äΤ֤ޤ
   
divide_c!(j, c)
    j ܤ c ǳޤ
   
divide_c(j, c)
    j ܤ c äΤ֤ޤ
   
mix_r!(i, j, c)
    i ܤ j ܤ c ܤ­ޤ
   
mix_r(i, j, c)
    i ܤ j ܤ c ܤ­Τ֤ޤ
   
mix_c!(i, j, c)
    i ܤ j ܤ c ܤ­ޤ
   
mix_c(i, j, c)
    i ܤ j ܤ c ܤ­Τ֤ޤ
   
left_eliminate!
    δѷǳʹѷޤ
   
    ͤϡѷΤ˻ȤäѤȡι󼰤Ǥ
   
    :
    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 = 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
   
left_inverse
    δѷˤ̵չǤ
   
left_sweep
    δѷǳʹˤ֤ޤ
   
step_matrix?
    ʹǤȤ(pivot)֤ޤǤʤȤnil ֤
    
   
kernel_basis
    ݤˤʤ٥ȥζ֤δ֤ޤƴ
    Algebra::Vector ǤǤ
   
    :
    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]
    end
   
determinant_by_elimination
    ξι󼰤ݤФˡǵޤ
   

