Location : Home > Languages > Perl > Package Title : Math::Matrix |
![]() |
Math::Matrix - 行列の乗算と逆行列
use Math::Matrix;
以下のメソッドが利用可能である。
new
コンストラクタの引数は同じ長さの配列参照のリストである。配列は複写される。エラー時にはを返す。
$a = new Math::Matrix ([rand,rand,rand], [rand,rand,rand], [rand,rand,rand]);
new がメソッドとして呼び出された場合には全ての要素が0で埋められた行列を返す。
clone
以下のように呼び出すことで行列を複写できる。
$b = $a->clone;
size
以下のように呼び出すことで行列の大きさを決定することができる。
($m, $n) = $a->size;
concat
同じ行数の2つの行列を連結する。結果は新しい行列またはエラー時の undef である。
$b = new Math::Matrix ([rand],[rand],[rand]); $c = $a->concat($b);
transpose
転置行列を返す。引数として渡された行列の行と列を入れ替える。
multiply
1つめの行列の行の大きさと2つめの列の長さの大きさが等しい2つの行列を乗じる。結果は積またはエラー時の undef である。
solve
行列により与えられた連立1次方程式を解く。列の数は行の数よりも大きくなければならない。変数が互いに従属であれば2つめ以降の変数に対する係数は 0 である。このことはメソッドがそのような連立方程式を扱えることを示している。メソッドは列に解を含む行列またはエラー時に undef を返す。
invert
solve を用いて逆行列を返す。
multiply_scalar
行列のスカラ倍を返す。
$a->multiply_scalar(2); 行列を2倍に
add
同じ次数の行列を足す。
substract
add($other->negative) のこと。
equal
2つの行列が等しいか否かを確認。行列の各要素の差が $Math::Matrix::eps 以下であることを確認する。
slice
列を抽出する。
a->slice(1,3,5);
determinant
行列式を計算する。
dot_product
2つのベクトルの内積を計算する。
absolute
ベクトルの絶対値を計算する。
normalizing
ベクトルを正規化する。
cross_product
Compute the cross-product of vectors.
行列を標準出力に出力する。追加的パラメータが指定されれば行列の表示前に出力される。
pinvert
擬似逆行列 ((A'A)^-1)A' を出力する。
use Math::Matrix; srand(time); $a = new Math::Matrix ([rand,rand,rand], [rand,rand,rand], [rand,rand,rand]); $x = new Math::Matrix ([rand,rand,rand]); $a->print("A\n"); $E = $a->concat($x->transpose); $E->print("Equation system\n"); $s = $E->solve; $s->print("Solutions s\n"); $a->multiply($s)->print("A*s\n");
Ulrich Pfeifer, <pfeifer@ls6.informatik.uni-dortmund.de>
Brian J. Watson, <bjbrew@power.net>
Matthew Brett, <matthew.brett@mrc-cbu.cam.ac.uk>
![]() |
Updated : 2007/03/07 |