Matrix

class Matrix

Represents a matrix of doubles. Internally represented as a SimpleMatrix from EJML.

Constructors

Link copied to clipboard
constructor(data: Array<DoubleArray>)

Constructor to create a Matrix from a 2D array.

constructor(data: Collection<Collection<Double>>)

Constructor to create a Matrix from a list of lists.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
@get:JvmName(name = "inverse")
val inverse: Matrix

The inverse of this matrix. The matrix must be square and invertible. If the matrix is not square, use pseudoInverse instead.

Link copied to clipboard
@get:JvmName(name = "norm")
val norm: Double

Returns the Frobenius norm of this matrix. The Frobenius norm is the square root of the sum of squares of all elements.

Link copied to clipboard

The number of columns in the matrix.

Link copied to clipboard

The number of rows in the matrix.

Link copied to clipboard
@get:JvmName(name = "pseudoInverse")
val pseudoInverse: Matrix

The pseudo-inverse of this matrix. The matrix must be square and invertible.

Link copied to clipboard

The size of the matrix.

Link copied to clipboard
@get:JvmName(name = "transpose")
val transpose: Matrix

The transpose of this matrix.

Functions

Link copied to clipboard
fun column(n: Int): Matrix

Returns the nth column of the matrix.

Link copied to clipboard
fun copy(): Matrix

Returns a copy of this matrix.

Link copied to clipboard

Returns the diagonal elements of this matrix.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
operator fun get(i: Int, j: Int): Double

Returns the element at the given indices.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Returns the LDLT decomposition of this matrix. Only works for symmetric matrices.

Link copied to clipboard

Returns the LLT (Cholesky) decomposition of this matrix. Only works for symmetric, positive-definite matrices. Provides in-place rank-1 update/downdate methods.

Link copied to clipboard

Returns the LU decomposition of this matrix.

Link copied to clipboard
operator fun minus(other: Matrix): Matrix

Subtracts another matrix from this matrix. The matrices must have the same dimensions.

Link copied to clipboard
operator fun plus(other: Matrix): Matrix

Adds another matrix to this matrix. The matrices must have the same dimensions.

Link copied to clipboard

Returns the QR decomposition of this matrix.

Link copied to clipboard
fun row(n: Int): Matrix

Returns the nth row of the matrix.

Link copied to clipboard
operator fun set(i: Int, j: Int, value: Double)

Sets the element at the given indices to the given value.

Link copied to clipboard
fun slice(startRow: Int, endRow: Int, startCol: Int, endCol: Int): Matrix

Returns a submatrix of this matrix.

Link copied to clipboard
fun solve(other: Matrix): Matrix
Link copied to clipboard
operator fun times(other: Matrix): Matrix

Multiplies this matrix by another matrix. The number of columns in this matrix must match the number of rows in the other matrix.

operator fun times(scalar: Double): Matrix
operator fun times(scalar: Int): Matrix

Multiplies this matrix by a scalar.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
operator fun unaryMinus(): Matrix

Returns the matrix with all elements negated. This is equivalent to multiplying the matrix by -1.