Skip to content

qibin0506/KtMatrix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KtMatrix

A kotlin implemention of Matrix, support add, multipy, dot, transpose, inverse, determinant, trace, adjugate matrix and etc.

  1. init

get a 3x3 matrix and initialize the value.

val mat = Mat(3, 3) {
    arrayOf(
            1, 2, 3,
            1, 0, -1,
            0, 1, 1
    )
}

or, get a 3x3 identity matrix by using,

val mat = identity(3)
  1. get value

get the value at position (i, j)

println(mat[i, j])

or, dump the full matrix by using,

print(mat)
  1. set value

set the value at position (i, j)

mat[i, j] = 10.0
  1. transpose
println(mat.T)
  1. inverse
println(mat.I)
  1. addition
println(mat + mat2)
println(mat + 2.0)
  1. minus
println(mat - mat2)
println(mat - 2.0)
  1. element-wise product
println(mat * mat2)
println(mat * 2.0)
  1. dot product
println(mat.dot(mat2))
  1. element-wise div
println(mat / mat2)
println(mat / 2.0)
  1. determinant
println(mat.det())
  1. trace
println(mat.trace())
  1. adjugate matrix
println(mat.adj())

About

A kotlin implemention of Matrix

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages