| Path: | matrix.rb |
| Last Update: | Sat Jul 19 22:33:44 GMT+10:00 2003 |
matrix.rb -
$Release Version: 1.0$
$Revision: 1.11 $
$Date: 1999/10/06 11:01:53 $
Original Version from Smalltalk-80 version
on July 23, 1985 at 8:37:17 am
by Keiju ISHITSUKA
—
Matrix[[1,2,3],
:
[3,4,5]]
Matrix[row0,
row1,
:
rown]
| module ExceptionForMatrix: | Exceptions:
ErrDimensionMismatch
number of column/row do not match
ErrNotRegular
not a regular matrix
ErrOperationNotDefined
specified operator is not defined (yet)
|
class Matrix
include ExceptionForMatrix
Methods:
class methods:
Matrix.[](*rows)
creates a matrix where `rows' indicates rows.
`rows' is an array of arrays,
e.g, Matrix[[11, 12], [21, 22]]
Matrix.rows(rows, copy = true)
creates a matrix where `rows' indicates rows.
if optional argument `copy' is false, use the array as
internal structure of the metrix without copying.
Matrix.columns(columns)
creates a new matrix using `columns` as set of colums vectors.
Matrix.diagonal(*values)
creates a matrix where `columns' indicates columns.
Matrix.scalar(n, value)
creates a diagonal matrix such that the diagal compornents is
given by `values'.
Matrix.scalar(n, value)
creates an n-by-n scalar matrix such that the diagal compornent is
given by `value'.
Matrix.identity(n)
Matrix.unit(n)
Matrix.I(n)
creates an n-by-n unit matrix.
Matrix.zero(n)
creates an n-by-n zero matrix.
Matrix.row_vector(row)
creates a 1-by-n matrix such the row vector is `row'.
`row' is specifed as a Vector or an Array.
Matrix.column_vector(column)
creates a 1-by-n matrix such that column vector is `column'.
`column' is specifed as a Vector or an Array.
accessing:
[](i, j)
returns (i,j) compornent
row_size
returns the number of rows
column_size
returns the number of columns
row(i)
returns the i-th row vector.
when the block is supplied for the method, the block is iterated
over all row vectors.
column(j)
returns the jth column vector.
when the block is supplied for the method, the block is iterated
over all column vectors.
collect
map
creates a matrix which is the result of iteration of given
block over all compornents.
minor(*param)
returns sub matrix. parameter is specified as the following:
1. from_row, row_size, from_col, size_col
2. from_row..to_row, from_col..to_col
TESTING:
regular?
Is regular?
singular?
Is singular? i.e. Is non-regular?
square?
Is square?
ARITHMETIC:
*(m)
times
+(m)
plus
-(m)
minus
/(m)
self * m.inv
inverse
inv
inverse
**
power
Matrix functions:
determinant
det
returns the determinant
rank
returns the rank
trace
tr
returns the trace
transpose
t
returns the transposed
CONVERTING:
coerce(other)
row_vectors
array of row vectors
column_vectors
array of column vectors
to_a
converts to Array of Arrays
PRINTING:
to_s
returns string representation
inspect
class Vector
include ExceptionForMatrix
INSTANCE CREATION:
Vector.[](*array)
Vector.elements(array, copy = true)
ACCSESSING:
[](i)
size
ENUMRATIONS:
each2(v)
collect2(v)
ARITHMETIC:
*(x) "is matrix or number"
+(v)
-(v)
VECTOR FUNCTIONS:
inner_product(v)
collect
map
map2(v)
r
CONVERTING:
covector
to_a
coerce(other)
PRINTING:
to_s
inspect