Classiclll's Blog

an old boy

Locの仲間、Matを妄想中

Locの仲間、Matを妄想中。

[class] Mat              5/20/2008 by Classiclll
 * 線形代数(行列演算)のモデル
   添字の基数は0。すなわち
    elem(0, 0)     : 左上の行列要素(double)
      elem(row, col) : 左上から(row+1)番目の行、(col+1)番目の列の要素
 * [注意!]
   LU分解結果は下記メソッドでキャッシュされ、再利用される。
      solve(), isSingular(), det(), inverse()
   elemRef()で返される参照を通して内部で保持している行列が変更されてもキャッシュ
  されているLU分解結果はクリアされない。(できない)
  この場合、上のメソッドを使用する前に、LUDecompose() を明示的に呼び出す必要が
  ある

Body

 [members]
  no public member.
 
 [constructors]
 Mat()					:construct empty
 Mat(int rows, int cols)		:construct sized by rows*cols 
 Mat(double[][] d)			:construct having d[row][col]
 Mat(Mat m)				:construct having d[row][col]
 Mat(double[] v)			:construct single raw having v[col] 
 Mat(Vec v)				:construct having d[row][col]
 Mat(Loc v)				:construct 3D single row, (x,y,z)
 

[methods]

<group #0 - Matrix Operation - generator>
 Mat copy()			:return the copy of me.
 Mat getIdentity()			:return the identity mtx, sized by min(rows,cols)
 Mat add(Mat m)				:return me[i][j] + m[i][j]
 Mat add(double d)			:return me[i][j] + d (scalar)
 Mat sub(Mat m)				:return me[i][j] - m[i][j]
 Mat mul(double d)			:return me[i][j] - d (scalar)
 Mat mul(Mat m)				:return me[i][k] * m[k][j]
 Mat preMul(Mat m)			:return m[i][k] * me[k][j]
 Mat setSubMat(Mat subMat, int row, int col)	:ret[row+i][col+j] <= subMat[i][j] 
 Mat setSubMat(double[][] subMat, int row, int col): <same above > 	
 Mat setRowMat(Vec v, int row)	:return Mat({me[row][0],.....,me[row][col-1]})
 Mat setColMat(Vec v, int col)	:return {MAT(me[0][col],.....,me[row-1][col]})
 Mat SubMat(int startRow, int endRow,	:return me[sRow->eRow][sCol->eCol]
 			    int startCol, int endCol)
 Mat SubMat(int[] selectedRows,	:retturn {{.},..{me[selRow][selCol]},..{.}}
 			    int[] selectedCols)	
 Mat rowMat(int row)			:return Mat({me[row][0],.....,me[row][col-1]})
 Mat colMat(int col)			:return {MAT(me[0][col],.....,me[row-1][col]})
 Mat transpose()				:return the transpose of me.
 Mat inverse()			:"me" must be square, otherwize null returned
 
<group #1 - Vector Operation - generator>
 Vec rowVec(int row)			:return array({me[row][0],.....,me[row][col-1]})
 Vec colVec(int col)			:return array({me[0][col],.....,me[row-1][col]})
 Vec preMul(Vec v)			:reurn v[]*me[][]
 Vec operate(Vec v)			:return me[][]*transpose(v[])
 
<group #2 - Scalar - information>
 int rowDim()				:return the number of rows
 int colDim()				:return the numbrt of columns
 double elem(int row, int column)	:return the specified element
 double norm()			:return the infinit(=maximum) norm of me.
 double det()				:return the deturminant of me.
 double trace()			:return the trace of me.
 boolean isSquare()		:return is "me" square? (rows==columns)
 boolean isSingular()		:return is "me" singular?
 boolean equals(Object object)	:return shallow equolity between me and object 
 boolean hasNaN()		:return has me some Double.NaN 
 boolean hasInf()			:return has me some Double.Infinity
 boolean isNaN()			:return is me containing NaN or Infinity
 
 <group #3 - Utilities - generator>
 double[][] toArray()			:return 2d array of me
 double[][] arrayRef()			:retuen the reference to 2d array of "me"
 						modification may cause some trouble.
 String toString()                        	:get the string expression of me.
 
 <group #4 - High level operator>
 Vec solve(Vec b)
     : Returns a matrix of (column) solution vectors for linear systems with
            [me] * [x] = b[].
       when no solution, null refference will be returned.
 Mat solve(Mat b)
     : Returns a matrix of (column) solution vectors for linear systems with
            [me] * [x] = [b].
       when no solution, null refference will be returned.
 Mat luDecompose()
     :  Returns the LU decomposition of me as a Mat,
          a fresh copy of the cached LU matrix if this has been computed;
       When none chashed
          the composition is computed and cached for use by other methods.
          	solve(), isSingular(), det(), inverse()
       The matrix returned is a compact representation of the LU decomposition.
        *Example:
          Returned matrix          L                  U
              2  3  1           1  0  0            2  3  1
              5  4  6           5  1  0            0  4  6
              1  7  8           1  7  1            0  0  8
       The L and U matrices satisfy the matrix equation LU = permuteRows of me.
       when "me" is singular, null refference will be returned.
  【6月8日】更新