#=============================================== # MyMatrixReal #=============================================== package MyMatrixReal; #use Exporter; use Math::MatrixReal; @ISA = qw(Math::MatrixReal); #公開したいサブルーチン #@EXPORT = qw(aa ); use strict; #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new { my ($class, $pContent, $rows, $columns) = @_; my $this; if($pContent eq 'zero') { $rows = 1 if(!defined $rows); $columns = 1 if(!defined $columns); $this = new Math::MatrixReal($rows, $columns); bless $this,$class; $this->Zero(); } elsif($pContent eq 'unit') { $rows = 1 if(!defined $rows); $columns = 1 if(!defined $columns); $this = new Math::MatrixReal($rows, $columns); bless $this,$class; $this->UnitMatrix(); } elsif(defined $rows and !defined $columns) { $this = new Math::MatrixReal($pContent, $rows); bless $this,$class; } elsif(defined $rows) { print "Error in MyMatrixReal::new: Invalid Matrix Type [$pContent][$rows][$columns].\n"; exit; } else { $this = Math::MatrixReal->new_from_rows($pContent); bless $this,$class; } return $this; } sub DESTROY { my $this = shift; } #============================================================ # 静的関数 #============================================================ sub UnitMatrix { my ($this) = @_; return $this->one(); } sub Zero { my ($this) = @_; return $this->zero(); } sub e { my ($this, $row, $column) = @_; $row = 0 if(!defined $row); $column = 0 if(!defined $column); return $this->element($row, $column); } sub MakeDiagonalMatrix { my ($this, $pArray) = @_; return $this = Math::MatrixReal->new_diag($pArray); } sub dim { my ($this) = @_; return $this->dim(); } sub Determinant { my ($this) = @_; return $this->det(); } sub DiagonalizeSymmetricMatrix { my ($this) = @_; my ($l, $V) = $this->sym_diagonalize(); return ($l, $V); } sub DiagonalizeTridiagonalMatrix { my ($this) = @_; my ($l, $V) = $this->tri_diagonalize(); return ($l, $V); } sub Householder { my ($this) = @_; my ($T, $Q) = $this->householder(); return ($T, $Q); } sub LRDecomposition { my ($this) = @_; return $this->decompose_LR(); } sub inverse { my ($this) = @_; return $this->inverse(); } sub trace { my ($this) = @_; return $this->trace(); } sub transpose { my ($this, $m) = @_; $m = $this if(!defined $m); return $this->transpose($m); } sub LinearSolve { my ($M, $A) = @_; my ($rows, $columns) = $M->dim(); #print "r,c=$rows, $columns\n"; my $LR = $M->decompose_LR(); my ($dim, $solution, $base_matrix) = $LR->solve_LR($A); #print "Dim=$dim\n"; #print "Base=\n$base_matrix"; return $solution; } #$matrix->zero(); #$matrix->one(); Make '1' matrix #$matrix->assign($row,$column,$value); #my $value = $matrix->element($row,$column); # Do sub for each element: $matrix = $matrix->each( sub { (shift) + 1 } ); # Do sub for diagonal elements: $matrix = $matrix->each_diag( sub { (shift) + 1 } ); #$InvM123 = $M123->inverse(); #$M123->det(); #($l, $V) = $matrix->sym_diagonalize(); for n by n symmetric matrix #$l = $matrix->sym_eigenvalues(); # $l: eigen values, $V: engen vectors #($T, $Q) = $matrix->householder(); #$T = $matrix->householder_tridiagonal(); # convert n by n sym. matrix to a tridiagonal matrix # $T: symmetic tridiagonal matrix, $Q: transformation orthogonal matrix #($l, $V) = $T->tri_diagonalize([$Q]); for symmetric tridiagonal matrix #$l = $T->tri_eigenvalues(); #my ($rows,$columns) = $matrix->dim(); #$norm_max = $matrix->norm_max(); #$norm_sum = $matrix->norm_sum(); #$matrix1->transpose($matrix2); #$matrix1->add($matrix2,$matrix3); #$matrix1->subtract($matrix2,$matrix3); #$matrix1->multiply_scalar($matrix2,$scalar); #$product_matrix = $matrix1->multiply($matrix2); #$matrix1->negate($matrix2); = -$matrix2 #$matrix_to_power = $matrix1->exponent($integer); #$trace = $matrix->trace(); #$matrix1->copy($matrix2); #my $NewMatrix = $matrix1->clone(); #my $RowVector = $matrix->row(0); #$matrix->swap_col( $col1, $col2 ); #$matrix->swap_row( $row1, $row2 ); 1;