.NET GeneralMatrix class.
The .NET GeneralMatrix Class provides the fundamental operations of numerical linear algebra. Various constructors create Matrices from two dimensional arrays of double precision floating point numbers. Various "gets" and "sets" provide access to submatrices and matrix elements. Several methods implement basic matrix arithmetic, including matrix addition and multiplication, matrix norms, and element-by-element array operations. Methods for reading and printing matrices are also included. All the operations in this version of the GeneralMatrix Class involve real matrices. Complex matrices may be handled in a future version.
Five fundamental matrix decompositions, which consist of pairs or triples of matrices, permutation vectors, and the like, produce results in five decomposition classes. These decompositions are accessed by the GeneralMatrix class to compute solutions of simultaneous linear equations, determinants, inverses and other matrix functions.
The five decompositions are:
Example of use:
Solve a linear system A x = b and compute the residual norm, ||b - A x||.
double[][] vals;
GeneralMatrix A = New NumericMatrix(vals);
GeneralMatrix b = GeneralMatrix.Random(3,1);
GeneralMatrix x = A.Solve(b);
GeneralMatrix r = A.Multiply(x).Subtract(b);
double rnorm = r.NormInf();
Access the internal two-dimensional array. Pointer to the two-dimensional array of matrix elements. this numeric matrix object consist with a collection of Vector as rows.
05 Members
method
.ctor
overload 4
#
#ctor(Double())
Create a new (column) RealMatrix using {@code v} as the data for the unique column of the created matrix. The input array Is copied.
Remarks
20230815 创建一个只有一列数据的矩阵,矩阵的行数 等于v的元素数量
Parameters
| Name | Type | Description |
v | Double() | Column vector holding data for new matrix. |
method
.ctor
overload 8
#
#ctor(Int32, Int32)
Construct an m-by-n matrix of zeros. m is row number and n is column number
Remarks
m is row number and n is column number
Parameters
| Name | Type | Description |
m | Int32 | Number of rows. |
n | Int32 | Number of colums. |
method
.ctor
overload 7
#
#ctor(Int32, Int32, Double)
Construct an m-by-n constant matrix.
Parameters
| Name | Type | Description |
m | Int32 | Number of rows. |
n | Int32 | Number of colums. |
s | Double | Fill the matrix with this scalar value. |
method
.ctor
overload 5
#
#ctor(Double()(), Boolean)
Construct a matrix from a 2-D array.
Parameters
| Name | Type | Description |
A | Double()() | Two-dimensional array of doubles. |
t | Boolean | the given raw data parameter A is in columns required transpose of the matrix. |
method
.ctor
overload 2
#
#ctor(IEnumerable(Of Double()))
create a new numeric matrix based on a given collection of the row data vectors
Parameters
| Name | Type | Description |
rows | IEnumerable(Of Double()) | - |
method
.ctor
overload 6
#
#ctor(Double()(), Int32, Int32)
Construct a matrix quickly without checking arguments.
Parameters
| Name | Type | Description |
A | Double()() | Two-dimensional array of doubles. |
m | Int32 | Number of rows. |
n | Int32 | Number of colums. |
make the matrix value copy
Parameters
method
.ctor
overload 3
#
#ctor(Double(), Int32)
Construct a matrix from a one-dimensional packed array
Parameters
| Name | Type | Description |
vals | Double() | One-dimensional array of doubles, packed by columns (ala Fortran). |
m | Int32 | Number of rows. |
Block(Int32, Int32, Int32, Int32)
Parameters
| Name | Type | Description |
i | Int32 | the start location, col, x |
j | Int32 | the start location, row, y |
p | Int32 | the size of the block, nrows |
q | Int32 | the size of the block, ncols |
Create(Double()())
Construct a matrix from a copy of a 2-D array.
Parameters
| Name | Type | Description |
A | Double()() | Two-dimensional array of doubles. |
Copy
Make a deep copy of a matrix
Remarks
this function will break the array class reference between the matrix instance
GetMatrix(Int32, Int32, Int32, Int32)
Parameters
| Name | Type | Description |
i0 | Int32 | Initial row index |
i1 | Int32 | Final row index |
j0 | Int32 | Initial column index |
j1 | Int32 | Final column index |
Returns
method
GetMatrix
overload 4
#
GetMatrix(Int32(), Int32())
Parameters
| Name | Type | Description |
r | Int32() | Array of row indices. |
c | Int32() | Array of column indices. |
Returns
method
GetMatrix
overload 2
#
GetMatrix(Int32, Int32, Int32())
Parameters
| Name | Type | Description |
i0 | Int32 | Initial row index |
i1 | Int32 | Final row index |
c | Int32() | Array of column indices. |
Returns
method
GetMatrix
overload 3
#
GetMatrix(Int32(), Int32, Int32)
Parameters
| Name | Type | Description |
r | Int32() | Array of row indices. |
j0 | Int32 | Initial column index |
j1 | Int32 | Final column index |
Returns
Parameters
| Name | Type | Description |
i0 | Int32 | Initial row index |
i1 | Int32 | Final row index |
j0 | Int32 | Initial column index |
j1 | Int32 | Final column index |
X | GeneralMatrix | A(i0:i1,j0:j1) |
method
SetMatrix
overload 4
#
Parameters
| Name | Type | Description |
r | Int32() | Array of row indices. |
c | Int32() | Array of column indices. |
X | GeneralMatrix | A(r(:),c(:)) |
method
SetMatrix
overload 3
#
Parameters
| Name | Type | Description |
r | Int32() | Array of row indices. |
j0 | Int32 | Initial column index |
j1 | Int32 | Final column index |
X | GeneralMatrix | A(r(:),j0:j1) |
method
SetMatrix
overload 2
#
Parameters
| Name | Type | Description |
i0 | Int32 | Initial row index |
i1 | Int32 | Final row index |
c | Int32() | Array of column indices. |
X | GeneralMatrix | A(i0:i1,c(:)) |
Transpose
Remarks
make a value copy of the matrix
Returns
NormF
Returns
sqrt of sum of squares of all elements.
method
op_UnaryNegation
#
Returns
method
Subtract
overload 2
#
Subtract(Double)
Parameters
| Name | Type | Description |
B | Double | a numeric value |
Returns
Power(Double)
Parameters
| Name | Type | Description |
y | Double | power |
Returns
Element-by-element multiplication, C = A.*B
Parameters
Returns
method
ArrayMultiplyEquals
#
Element-by-element multiplication in place, A = A.*B
Parameters
Returns
method
ArrayRightDivide
#
Element-by-element right division, C = A./B
Parameters
Returns
method
ArrayRightDivideEquals
#
Element-by-element right division in place, A = A./B
Parameters
Returns
Element-by-element left division, C = A.\B
Parameters
Returns
method
ArrayLeftDivideEquals
#
Element-by-element left division in place, A = A.\B
Parameters
Returns
method
Multiply
overload 3
#
Multiply(Double)
Multiply a matrix by a scalar, C = s*A
Parameters
| Name | Type | Description |
s | Double | scalar |
Returns
method
Multiply
overload 2
#
Multiply a matrix by a scalar, C = s*A
Returns
Linear algebraic matrix multiplication, A * B
Jama.Matrix.times
Parameters
Returns
max(Int32, Int32)
maxCoeff, get max value in current matrix
Min(Int32, Int32)
minCoeff, get min value in current matrix
Parameters
| Name | Type | Description |
row | Int32 | - |
col | Int32 | - |
MultiplyEquals(Double)
Multiply a matrix by a scalar in place, A = s*A
Parameters
| Name | Type | Description |
s | Double | scalar |
Returns
method
op_Multiply
overload 2
#
Element-by-element multiplication of two matrices
Parameters
Element-by-element multiplication of two matrices
Parameters
method
op_Multiply
overload 3
#
Element-by-element multiplication of two matrices
Parameters
method
op_Multiply
overload 6
#
Multiplication of matrices
Parameters
| Name | Type | Description |
m2 | Double | - |
method
op_Multiply
overload 4
#
Multiplication of matrices
Parameters
method
op_Multiply
overload 5
#
Multiplication of matrices
Parameters
Element-by-element right division
Parameters
SVD
Singular Value Decomposition
Returns
SingularValueDecomposition
Parameters
Returns
solution if A is square, least squares solution otherwise
Solve XA = B, which is also A'X' = B'
Parameters
Returns
solution if A is square, least squares solution otherwise.
Inverse
Matrix inverse or pseudoinverse
Remarks
Returns
inverse(A) if A is square, pseudoinverse otherwise.
Determinant
GeneralMatrix determinant
Returns
Rank
Returns
effective numerical rank, obtained from SVD.
Condition
Matrix condition (2 norm)
Returns
ratio of largest to smallest singular value.
Trace
Returns
sum of the diagonal elements.
Identity(Int32, Int32)
Parameters
| Name | Type | Description |
m | Int32 | Number of rows. |
n | Int32 | Number of colums. |
Returns
An m-by-n matrix with ones on the diagonal and zeros elsewhere.
method
Identity
overload 2
#
Identity(Int32)
Create [m,m] identity matrix
Parameters
| Name | Type | Description |
m | Int32 | - |
method
CheckMatrixDimensions
#
Check if size(A) == size(B) *
Remarks
Dispose
Do not make this method virtual. A derived class should not be able to override this method.
method
Dispose
overload 2
#
Dispose(Boolean)
Dispose(bool disposing) executes in two distinct scenarios. If disposing equals true, the method has been called directly or indirectly by a user's code. Managed and unmanaged resources can be disposed. If disposing equals false, the method has been called by the runtime from inside the finalizer and you should not reference other objects. Only unmanaged resources can be disposed.
Parameters
| Name | Type | Description |
disposing | Boolean | - |
Finalize
This destructor will run only if the Dispose method does not get called. It gives your base class the opportunity to finalize. Do not provide destructors in types derived from this class.
Resize(Int32, Int32)
Parameters
| Name | Type | Description |
m | Int32 | - |
n | Int32 | - |
Clone
Clone the GeneralMatrix object.
ArrayPack(Boolean)
Copy the internal two-dimensional array.
Returns
Two-dimensional array copy of matrix elements.
One(Int32, Int32)
fill numeric value 1 to matrix with dimension size [columnDimension x rowDimension]
Parameters
| Name | Type | Description |
columnDimension | Int32 | - |
rowDimension | Int32 | - |
Gauss(Int32, Int32)
create a random matrix with dimension size [columnDimension x rowDimension]
Remarks
element data range that generats inside the matrix is [-1,1]
Parameters
| Name | Type | Description |
columnDimension | Int32 | - |
rowDimension | Int32 | - |
random(Int32, Int32, Double, Double)
create a random matrix with dimension size [columnDimension x rowDimension]
Parameters
| Name | Type | Description |
columnDimension | Int32 | - |
rowDimension | Int32 | - |
矩阵乘积(matrix product,也叫matmul product):A 的列数必须和 B 的行数相等
Parameters
property
ColumnPackedCopy
#
ColumnPackedCopy
Make a one-dimensional column packed copy of the internal array.
Returns
Matrix elements packed in a one-dimensional array by columns.
RowPackedCopy
Make a one-dimensional row packed copy of the internal array.
Returns
Matrix elements packed in a one-dimensional array by rows.
property
ColumnDimension
#
ColumnDimension
Returns
n, the number of columns.
Dimension
Returns
the width is the number of columns(n) and the height is the number of rows(m)
property
Item
overload 3
#
Item(Int32, Int32)
Parameters
| Name | Type | Description |
i | Int32 | Row index. |
j | Int32 | Column index. |
Returns
property
Item
overload 4
#
Item(UInt32, UInt32)
Parameters
| Name | Type | Description |
i | UInt32 | Row index. |
j | UInt32 | Column index. |
Returns
Item(IEnumerable(Of Int32))
column projection via column index
Remarks
select column values for each row for create a new matrix
Parameters
| Name | Type | Description |
indices | IEnumerable(Of Int32) | - |
property
Item
overload 2
#
Item(Int32, Boolean)
get/set data vector by row or by column
Parameters
| Name | Type | Description |
i | Int32 | - |
byRow | Boolean | - |
m
Row and column dimensions. @serial row dimension.
n
Row and column dimensions. @serial column dimension.
property
DiagonalVector
#
DiagonalVector
method
Create
overload 2
#
Create(Int32, Int32)
Diagonal(Int32, Int32, Double)
method
GetRectangularArray
#
method
ConvertJaggedToRectangularFlexible
#
ConvertJaggedToRectangularFlexible(Double()())
RowApply(Func(Of Double(), Int32, T))