Skip to content

inv

Matrix inverse

inv x     inv[x]

Returns the inverse of the non-singular float matrix x.

q)a:3 3#2 4 8 3 5 6 0 7 1f
q)inv a
-0.4512195  0.6341463  -0.195122
-0.03658537 0.02439024 0.1463415
0.2560976   -0.1707317 -0.02439024
q)a mmu inv a
1 2.220446e-16 -5.551115e-17
0 1            -2.775558e-17
0 0            1
q)1=a mmu inv a
100b
010b
001b

x must be a square float matrix: other types signal a type error, and a non-square matrix signals a length error. The inverse of a singular matrix is a matrix of nulls.

q)inv 3 3#2 4 8 3 5 6 0 7 1
'type
  [0]  inv 3 3#2 4 8 3 5 6 0 7 1
       ^
q)0N!inv 2 2#1f;
(0n 0n;0n 0n)

inv uses LU (lower–upper) decomposition. To solve a linear system, use lsq, which solves a normal equations matrix using Cholesky decomposition: solving the system directly is more robust than inverting the matrix and multiplying.


lsq

Mathematics

LU decomposition, Cholesky decomposition