Matrix class
The Matrix class
Most of the class code is not optimized for high performance but for readability. You should be able to read the functions and understand what is going on with basic linear algebra knowledge.
For more reading see the page about Matrix Math at Wikipedia
(Matrix
final Matrix a = Matrix([[1, 2], [3, 4]]);
final Vector b = Vector.column([2, 3]);
final Matrix e = Matrix([[8], [18]]);
Matrix result = a * b;
print(result);
print(result == e);
This prints
[[8.0], [18.0]]
true
Constructors
-
Matrix.new(List<
List< _values)double> > - Constructs a matrix from a List<List
- Matrix.eye(int size)
-
Constructs an identity matrix of
size
- Matrix.fill(int m, int n, [double fill = 0.0])
-
Constructs a
m
xn
(rows x cols) Matrix fill withfill=0.0
.
Properties
Methods
-
coFactors(
) → Matrix - Calculates the Cofactors of the matrix.
-
columnVector(
int column) → Vector - Returns a column from the matrix as a vector.
-
copy(
) → Matrix - Returns a deep copy of the Matrix.
-
cut(
int m, int n) → Matrix -
Cuts the given column
m
and rown
from the matrix and returns the remainder. -
det(
) → double - Calculates the determinant of the matrix.
-
inverse(
) → Matrix - Calculates the matrix inverse.
-
map(
MatrixMapFunc f) → Matrix -
Calls
f
for each element in the matrix and stores the result in a new matrix. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
rowVector(
int row, [bool deepCopy = true]) → Vector - Returns a row from the matrix as a vector.
-
toString(
) → String -
Prints the content of the matrix.
override
-
toVector(
[bool deepCopy = true]) → Vector - Returns the Vector representation of this Matrix if one of it's dimensions is 1.
-
trace(
) → double - Calculates the trace of the Matrix.
-
transpose(
) → Matrix - Transposes the matrix
Operators
-
operator *(
dynamic other) → Matrix - Multiply an Matrix with a Matrix or a scalar
-
operator +(
Matrix other) → Matrix - Add two matrices of same dimensions.
-
operator -(
Matrix other) → Matrix - Subtract two matrices of same dimensions.
-
operator ==(
dynamic other) → bool -
Equality check for each element in the matrix.
override
-
operator [](
int m) → List< double> - Access a row of data from the matrix
-
operator ~(
) → Matrix - Negate all values