Ruby 1.9.2 リファレンスマニュアル > ライブラリ一覧 > matrixライブラリ > Matrixクラス
クラスの継承リスト: Matrix < Enumerable < Object < Kernel < BasicObject
数Numericを要素とする行列を扱うクラスです。
行列
m * n 個の数a(i,j)を
[ a(0,0) a(0,1) a(0,2) a(0,3) ... a(0,n-1) ] [ a(1,0) a(1,1) a(1,2) a(1,3) ... a(1,n-1) ] [ a(2,0) a(2,1) a(2,2) a(2,3) ... a(2,n-1) ] [ ] [ a(m-1,0) a(m-1,n-1) ]
のように、縦横の表にあらわしたものを(m,n)型の行列という。 m=nの行列をm次の正方行列(square matrix)という。
上からi番目の横の数の並びを第i行(the i-th row)、 左からj番目の縦の数の並びを第j列(the j-th column)という。
(m,n)型行列は、 大きさnの行(横)ベクトルをm個縦に並べたものとみなすこともできるし、 大きさmの列(縦)ベクトルをn個横に並べたものとみなすこともできる。
第i行、第j列にある数a(i,j)を(i,j)要素(the (i,j)-th element)という。
i=jの要素a(i,j)を対角要素(diagonal element)、 それ以外の要素を非対角要素(nondiagonal element)という。
require 'complex'することによって、 Matrixオブジェクトの要素はComplexクラスに拡張される。 多くのメソッドは、この拡張されたMatrixクラスでも、期待通りに動作する。
次の例は、各要素を共役複素数に置換するメソッド Matrix#conjugate である。
require 'matrix' require 'complex' class Matrix def conjugate collect{|e| e.conjugate } end end
定義 | 説明 | |
---|---|---|
identity(n) -> Matrix
|
n次の単位行列を生成します。 |
|
self[rows] -> Matrix
|
rowsを要素とする行列を生成します。 配列を行列の行成分として行列を生成します。 |
|
build(row_size, column_size) {|row, col| ... } -> Matrix
|
Creates a matrix of size +row_size+ x +column_size+. It fills the values by calling the given block, passing the current row and column. Returns an enumerator if no block is given. |
|
column_vector(column) -> Matrix
|
要素がcolumnの(n,1)型の行列(列ベクトル)を生成します。 |
|
columns(columns) -> Matrix
|
引数 columns を列ベクトルの集合とする行列を生成します。 |
|
diagonal(values) -> Matrix
|
対角要素がvalues(オブジェクトの並び)で、非対角要素が全て0であるような 正方行列を生成します。 |
|
row_vector(row) -> Matrix
|
要素がrowの(1,n)型の行列(行ベクトル)を生成します。 |
|
rows(rows, copy = true) -> Matrix
|
引数 rows を要素とする行列を生成します。 引数 copy が偽(false)ならば、rows の複製を行いません。 |
|
scalar(n, value) -> Matrix
|
対角要素が全てvalue(数)で、非対角要素が全て0であるようなn次の正方行列を生成します。 |
|
zero(n) -> Matrix
|
n次の零行列を生成します。 零行列とは、要素が全て0の行列です。 |
定義 | 説明 | |
---|---|---|
self * m -> Matrix
|
行列mを右から乗じた行列を返します。 |
|
self ** n -> Matrix
|
self の n乗をした行列を返します。 |
|
self + m -> Matrix
|
行列mを加算した行列を返します。 |
|
self - m -> Matrix
|
行列mを減算した行列を返します。 |
|
self / m -> Matrix
|
行列mの逆行列を右から乗じた行列を返します。 |
|
self == other -> bool
|
自分自身と other を比較し、同値であれば真(true)を返します。 |
|
self[i, j] -> ()
|
(i,j)要素を返します。 |
|
clone -> Matrix
|
自分自身のコピーを返します。 |
|
coerce(other) -> Array
|
他の数値オブジェクトとの変換を行います。 |
|
collect {|x| ... } -> Matrix
|
行列の各要素に対してブロックの適用を繰り返した結果を、要素として持つ行列を生成します。 |
|
column(j) -> Vector
|
第j番目の列ベクトルを返します。 |
|
column_size -> Fixnum
|
列の大きさを返します。 |
|
column_vectors -> Array
|
自分自身を列ベクトルの配列として返します。 |
|
conjugate -> Matrix
|
Returns the conjugate of the matrix. |
|
determinant -> Rational | Float
|
行列式 (determinant) を返します。 |
|
determinant_e -> Rational | Float
|
行列式 (determinant) を返します。 |
|
each {|e| ... } -> self
|
Yields all elements of the matrix, starting with those of the first row, or returns an Enumerator is no block given |
|
each_with_index {|e, row, col| ... } -> self
|
Yields all elements of the matrix, starting with those of the first row, along with the row index and column index, or returns an Enumerator is no block given |
|
elements_to_f -> Array
|
各要素を浮動小数点数 Float に変換した行列を返します。 |
|
elements_to_i -> Array
|
各要素を整数 Integer に変換した行列を返します。 |
|
elements_to_r -> Array
|
各要素を有理数 Rational に変換した行列を返します。 |
|
empty? -> bool
|
Returns +true+ if this is an empty matrix, i.e. if the number of rows or the number of columns is 0. |
|
hash -> Fixnum
|
行列のHash値を返します。 |
|
imaginary -> Matrix
|
Returns the imaginary part of the matrix. |
|
inspect -> String
|
自分自身を見やすい形式に文字列化し、その文字列を返します。 |
|
inverse -> Matrix
|
逆行列を返します。 |
|
inverse_from(src) -> Matrix
|
行列1次方程式の解(の行列)を返します。 |
|
minor(from_row, row_size, from_col, col_size) -> Matrix
|
selfの部分行列を返します。 |
|
rank -> Fixnum
|
階数 (rank) を返します。 |
|
rank_e -> Fixnum
|
階数 (rank) を返します。 |
|
real -> Matrix
|
Returns the real part of the matrix. |
|
real? -> bool
|
Returns +true+ if all entries of the matrix are real. |
|
rectangular -> [Matrix, Matrix]
|
Returns an array containing matrices corresponding to the real and imaginary parts of the matrix |
|
regular? -> bool
|
正則(regular)なら真(true)を返します。 |
|
row(i) -> Vector
|
第i番目の行ベクトルを返します。 |
|
row_size -> Fixnum
|
行の大きさを返します。 |
|
row_vectors -> Array
|
自分自身を行ベクトルの配列として返します。 |
|
singular? -> bool
|
特異(singular)なら真(true)を返します。 |
|
square? -> bool
|
正方行列であるなら、真を返します。 |
|
transpose -> Matrix
|
転置行列 (transpose matrix) を返します。 |
|
to_a -> Array
|
自分自身をArrayに変換したものを返します。 |
|
to_s -> String
|
行列を文字列化し、その文字列を返します。 |
|
trace -> Fixnum | Float | Rational
|
トレース (trace) を返します。 |
!
!=
all?
any?
chunk
collect_concat
count
cycle
detect
drop
drop_while
each_cons
each_entry
each_slice
each_with_object
entries
find_all
find_index
first
grep
group_by
include?
inject
max
max_by
min
min_by
minmax
minmax_by
none?
one?
partition
reject
reverse_each
slice_before
sort
sort_by
take
take_while
to_set
zip
===
=~
__id__
__send__
_dump
class
clone
dclone
display
enum_for
equal?
extend
freeze
frozen?
initialize
initialize_copy
instance_eval
instance_exec
instance_of?
instance_variable_defined?
instance_variable_get
instance_variable_set
instance_variables
is_a?
marshal_dump
marshal_load
method
method_missing
methods
must_be
must_be_close_to
must_be_empty
must_be_instance_of
must_be_kind_of
must_be_nil
must_be_same_as
must_be_within_epsilon
must_equal
must_include
must_match
must_raise
must_respond_to
must_send
must_throw
nil?
pretty_inspect
pretty_print
pretty_print_cycle
pretty_print_inspect
pretty_print_instance_variables
private_methods
protected_methods
public_methods
remove_instance_variable
respond_to?
respond_to_missing?
singleton_class
singleton_method_added
singleton_method_removed
singleton_method_undefined
singleton_methods
taint
tainted?
tap
to_ary
to_hash
to_int
to_io
to_proc
to_regexp
to_str
to_yaml
to_yaml_properties
to_yaml_style
trust
untaint
untrust
untrusted?
wont_be
wont_be_close_to
wont_be_empty
wont_be_instance_of
wont_be_kind_of
wont_be_nil
wont_be_same_as
wont_be_within_epsilon
wont_equal
wont_include
wont_match
wont_respond_to
.new