public abstract class Matrix extends Vector
nCols()
,elt(r,c)
,Vector
s. Also see Matrix.GP2
. And note
that a non-rectangular, "jagged" Vector of Vectors can be created
as, say, a Vector.GP
of GPs.Modifier and Type | Class and Description |
---|---|
static class |
Matrix.Doubles
Matrices of Reals (Cts, doubles).
|
static class |
Matrix.GP2
A simple, general-purpose implementation of a
Matrix . |
static class |
Matrix.Ints
Matrices of Ints (ints).
|
class |
Matrix.Jacobi
The Jacobi algorithm finds the Eigen-Values and Eigen-Vectors of
'this' square, symmetric Matrix of Cts; it is usually
invoked via
eigen() , eigenValues() , or
eigenVectors() . |
Vector.Derived, Vector.GP, Vector.Slice, Vector.Strings, Vector.Weighted
Value.Atomic, Value.Bool, Value.Char, Value.Chars, Value.Cts, Value.Defer, Value.Discrete, Value.Enum, Value.Inc_Or, Value.Int, Value.Lambda, Value.List, Value.Maybe, Value.Option, Value.Real, Value.Scannable, Value.Structured, Value.Triv, Value.Tuple
Constructor and Description |
---|
Matrix()
The trivial constructor for use when the number of columns is
not known before calling a Matrix constructor.
|
Matrix(int nC)
Constructor for use when the number of columns, nC, is known
before calling the constructor, and the Matrix is known to
be proper (rectangular).
|
Modifier and Type | Method and Description |
---|---|
Matrix |
asMatrix()
Return 'this'; also see
Vector.asMatrix() . |
static Matrix.Doubles |
doubles(double[][] xs)
Convenience function
: double[][] → Matrix, where each
elt(r,c) is an exact
Real . |
static Matrix.Doubles |
doubles(double[][] xs,
double AoM)
Convenience function,
doubles : double[][] × AoM → Matrix, where
every element of the Matrix has the same
AoM() . |
Value.Tuple |
eigen()
Return the Eigen-Values and Eigen-Vectors,
Matrix.Jacobi algorithm. |
Vector |
eigenValues()
Return the Eigen-Values of 'this' square, symmetric Matrix.
|
Matrix |
eigenVectors()
Return the Eigen-Vectors of 'this' square, symmetric Matrix.
|
Vector |
elt(int r)
Row 'r' (top-level element r) of 'this' Matrix; a sub-class of
Matrix might be able to provide a more efficient version than
this default.
|
abstract Value |
elt(int r,
int c)
The Matrix element at position c of
elt(r) ,
that is at column c of row r of 'this' Matrix. |
Matrix |
elts(int[] rs,
int[] cs)
Return the sub-Matrix with rows, rs, and columns, cs.
|
Type |
eltType()
The element Type of 'this' Matrix must be
VECTOR . |
static Matrix |
fromLexical(Lexical lex)
Read a Matrix of Cts from
Lexical analyser, 'lex', such as a
Lexical.forFile(fname) , say. |
Matrix |
GJ_fp()
GJ_fp, the Gauss-Jordan (GJ) elimination algorithm with full row
and column pivoting (fp); also see
inverse() . |
static Matrix |
id(int N)
Return the N×N identity Matrix of Ints;
note, is static.
|
static Matrix.Ints |
ints_UR(boolean incDiag,
int[][] ns,
int diagV)
Make a symmetric Int Matrix from 'ns' which is an
upper-right triangular array of array of int.
|
static Matrix.Ints |
ints(int[][] ns)
Convenience function,
ints : int[][] →
Matrix . |
Matrix |
inverse()
Return the inverse of a (square, non-singular) Matrix
by
GJ_fp() . |
boolean |
isRectangular()
True, every Matrix is rectangular by definition.
|
boolean |
isSquare()
|
double |
logDeterminant()
Return the log of the determinant of 'this'
square, symmetric Matrix.
|
static void |
main(java.lang.String[] argv)
main() allows Vector to be (slightly) tested, in isolation.
|
int |
nCols()
The number of colums; note every Matrix is rectangular.
|
abstract int |
nElts()
The number of rows (top-level elements) in 'this' Matrix.
|
int |
nElts(int r)
Return
nCols() ; note that every Matrix is rectangular. |
protected int |
nEltsRaw(int r)
Called in the rectangularity-check within
setNcols(int)
if the constructor Matrix() was used; it need not be implemented
(overridden) if Matrix(nC) was used. |
int |
rowLength()
Every row of 'this' Matrix has
nCols() elements. |
protected void |
setNcols(int nC)
If the trivial constructor, Matrix(), has been used, a
sub-class of Matrix must override
nEltsRaw(int) and call
setNcols(nC) before nCols()
(or nElts(r) ) is used. |
double |
slowDeterminant()
Calculate the determinant of 'this' Matrix by the slow, recursive
(naive) method.
|
Matrix |
times(Matrix M)
Matrix-multiplication of two matrices of Cts, 'this' and M.
|
Vector |
times(Vector v)
'this' Matrix, M, times the Vector of Cts, v, as a column-Vector,
as in
times(Matrix) . |
Matrix |
transpose()
Return the transpose of 'this' Matrix.
|
static Matrix.GP2 |
values(Value[][] vs)
Convenience function,
values : Value[][] →
GP2 . |
addMore, addMore, append, append, as_1xn, as_nx1, asDiagonal, asQ, asQrotn, bOp, closes, col, cols, combine, compareTo, constAoM, constNlAoM, constWt, csv, csv, delete, delete, dot, doubles, doubles, doubles, drop, drop, dropLast, elts, foldl, foldl, foldr, foldr, fromScannable, ints, ints, map, match, merge, nearlySymmetric, nearlySymmetric, nlAoM, nlAoM, norm_Cts, norm, normalised, normalised1, normalised2, opens, repeat, rotate, rotate, scaled, shape, singleton, slice, sorted, sorted, sorted, strings, sumSq, take, takeLast, toSeries, type, uniqueElts, unzip, unzip, uOp, values, weight, weight, weight, weightLike, weightLike, wt, wtMedian, wtNlAoM, wtNlAoM, wts, wts, zip, zip
AoM, elts, frth, fst, print, separator, snd, thrd, toString
public Matrix(int nC)
setNcols(int)
must not be
called and nEltsRaw(int)
need not be implemented --
also see Matrix().public Matrix()
setNcols(int)
, and constructor Matrix(nC).protected void setNcols(int nC)
nEltsRaw(int)
and call
setNcols(nC) before nCols()
(or nElts(r)
) is used.protected int nEltsRaw(int r)
setNcols(int)
if the constructor Matrix() was used; it need not be implemented
(overridden) if Matrix(nC) was used. See nElts(int)
.public Type eltType()
VECTOR
.
Also see Vector.eltType()
.public abstract int nElts()
nCols()
.public int nCols()
public Vector elt(int r)
elt(r,c)
.
public int nElts(int r)
nCols()
; note that every Matrix is rectangular.public abstract Value elt(int r, int c)
elt(r)
,
that is at column c of row r of 'this' Matrix.public Matrix elts(int[] rs, int[] cs)
Vector.slice(int, int)
.public boolean isRectangular()
isRectangular
in class Vector
public int rowLength()
nCols()
elements.public Matrix asMatrix()
Vector.asMatrix()
.public static Matrix id(int N)
public Vector times(Vector v)
times(Matrix)
.public Matrix transpose()
wt(r)
is 1.0 for all r.public Matrix GJ_fp()
inverse()
.public Value.Tuple eigen()
Matrix.Jacobi
algorithm.
Also see eigenValues()
and eigenVectors()
.public Vector eigenValues()
eigen()
.public Matrix eigenVectors()
eigen()
.public double logDeterminant()
Eigen-values
.public double slowDeterminant()
logDeterminant()
.public static Matrix fromLexical(Lexical lex)
Lexical
analyser, 'lex', such as a
Lexical.forFile(fname)
, say.
Elements (columns) are separated by white space,
rows by newline(s). AoM is guessed from the data.public static Matrix.GP2 values(Value[][] vs)
GP2
.
Also see the 1D Vector.values(Value[])
.public static Matrix.Ints ints(int[][] ns)
Matrix
.
Also see the 1D Vector.ints(int[])
.public static Matrix.Ints ints_UR(boolean incDiag, int[][] ns, int diagV)
public static Matrix.Doubles doubles(double[][] xs, double AoM)
AoM()
.
Also see the 1D Vector.doubles(double[],double)
.public static Matrix.Doubles doubles(double[][] xs)
Real
.
Also see the 1D Vector.doubles(double[])
.public static void main(java.lang.String[] argv)