Últimas Arquivo Comunicados

l4P5 (beta-003)2009-05-05 20:38
Loc (beta-005)2009-05-05 20:33
wrj4p5 (alpha-011)2009-05-05 20:41

最近の更新

2012-01-01
2010-03-25
2009-12-26
2009-05-06
2009-04-12
2009-03-02
2008-12-20
2008-08-08

Wikiガイド

サイドバー

ClassMat - the model of Linear Algebra with the linear operations

test applet and code is here

  1. /*[class] Mat 5/20/2008 by Classiclll
  2. * the model of Linear Algebra with the linear operations.
  3. * The index of Matrices is 0-based -- e.g.,
  4. * elem(0, 0) : the element in the first row, first column
  5. * elem(n, m) : the element in the (n-1)th. row, (m-1)th column.
  6. *
  7. * can solve the linear equations, with LU decomposition
  8. * [[cij]] * [xj] = [bj]
  9. *
  10. * [Caution!]
  11. * The LU matrix is cached and reused on subsequent calls,
  12. * solve(), isSingular(), det(), inverse()
  13. * If data are modified via references getDataRef(), then the
  14. * stored LU decomposition will not be discarded. In this case,
  15. * you need to explicitly invoke LUDecompose() to recompute
  16. * The LU decomposition is performed before using any of the
  17. * methods above.
  18. */
  19. [members]
  20. static final Mat NaN //constant Mat of one Double.NaN(not a number)
  21. [constructer]
  22. Mat() //construct empty
  23. Mat(int rows, int cols) //construct sized by rows*cols
  24. Mat(double d, int rows, int cols)//construct sized by rows*cols, all having d
  25. Mat(double[][] d) //construct having d[row][col]
  26. Mat(Mat m) //construct having d[row][col]
  27. Mat(double[] v) //construct single raw having v[col]
  28. Mat(Vec v) //construct having d[row][col]
  29. Mat(Loc v) //construct 3D single row, (x,y,z)
  30. [methods]
  31. <group #0 - Matrix Operation - generator>
  32. Mat copy() //return the copy of me.
  33. Mat getIdentity() //return the identity mtx, sized by min(rows,cols)
  34. Mat add(Mat m) //return me[i][j] + m[i][j]
  35. Mat add(double d) //return me[i][j] + d (scalar)
  36. Mat sub(Mat m) //return me[i][j] - m[i][j]
  37. Mat mul(double d) //return me[i][j] - d (scalar)
  38. Mat mul(Mat m) //return me[i][k] * m[k][j]
  39. Mat preMul(Mat m) //return m[i][k] * me[k][j]
  40. Mat setSubMat(Mat subMat, int row, int col)//ret[row+i][col+j] <= subMat[i][j]
  41. Mat setSubMat(double[][] subMat, int row, int col)// <same above>
  42. Mat setRowMat(Vec v, int row) //return Mat({me[row][0],.....,me[row][col-1]})
  43. Mat setColMat(Vec v, int col) //return {MAT(me[0][col],.....,me[row-1][col]})
  44. Mat SubMat(int startRow, int endRow,//return me[sRow->eRow][sCol->eCol]
  45. int startCol, int endCol)
  46. Mat SubMat(int[] selectedRows,//retturn {{.},..{me[selRow][selCol]},..{.}}
  47. int[] selectedCols)
  48. Mat rowMat(int row) //return Mat({me[row][0],.....,me[row][col-1]})
  49. Mat colMat(int col) //return {MAT(me[0][col],.....,me[row-1][col]})
  50. Mat transpose() //return the transpose of me.
  51. Mat inverse() //"me" must be square, otherwize null returned
  52. <group #1 - Vector Operation - generator>
  53. Vec rowVec(int row) //return array({me[row][0],.....,me[row][col-1]})
  54. Vec colVec(int col) //return array({me[0][col],.....,me[row-1][col]})
  55. Vec preMul(Vec v) //reurn v[]*me[][]
  56. Vec operate(Vec v) //return me[][]*transpose(v[])
  57. <group #2 - Scalar - information>
  58. int rowDim() //return the number of rows
  59. int colDim() //return the numbrt of columns
  60. double elem(int row, int column) //return the specified element
  61. double norm() //return the infinit(=maximum) norm of me.
  62. double det() //return the deturminant of me.
  63. double trace() //return the trace of me.
  64. boolean isSquare() //return is "me" square? (rows==columns)
  65. boolean isSingular() //return is "me" singular?
  66. boolean equals(Object object) //return shallow equolity between me and object
  67. boolean hasNaN() //return has me some Double.NaN
  68. boolean hasInf() //return has me some Double.Infinity
  69. boolean isNaN() //return is me containing NaN or Infinity
  70. <group #3 - Utilities - generator>
  71. double[][] toArray() //return 2d array of me
  72. double[][] arrayRef() //retuen the reference to 2d array of "me"
  73. // *modification may cause some trouble.
  74. String toString() //get the string expression of me.
  75. <group #4 - High level operator>
  76. Vec leqValueAt(Vec x) //same as operate(Vec x)
  77. Vec solve(Vec b)
  78. // Returns a matrix of (column) solution vectors for linear systems with
  79. [me] * [x] = b[].
  80. // when no solution, null refference will be returned.
  81. Mat solve(Mat b)
  82. // Returns a matrix of (column) solution vectors for linear systems with
  83. [me] * [x] = [b].
  84. // when no solution, null refference will be returned.
  85. Mat luDecompose()
  86. // Returns the LU decomposition of me as a Mat,
  87. /* a fresh copy of the cached LU matrix if this has been computed;
  88. When none chashed
  89. the composition is computed and cached for use by other methods.
  90. solve(), isSingular(), det(), inverse()
  91. The matrix returned is a compact representation of the LU decomposition.
  92. *Example :
  93. Returned matrix L U
  94. 2 3 1 1 0 0 2 3 1
  95. 5 4 6 5 1 0 0 4 6
  96. 1 7 8 1 7 1 0 0 8
  97. The L and U matrices satisfy the matrix equation LU = permuteRows of me.
  98. when "me" is singular, null refference will be returned. */