Matrix Inverse
⌹
|
Matrix Inverse (⌹
) is a monadic primitive function that returns the inverse of a simple numeric array of rank 2 or lower. Some dialects automatically apply it to rank-2 subarrays of higher-rank arguments. It shares the glyph Quad Divide <source lang=apl inline>⌹</syntaxhighlight> (often called Domino) with the dyadic function Matrix Divide.
Examples
Matrix Inverse computes the ordinary inverse if the argument is a square matrix. DOMAIN ERROR is raised if the given matrix is not invertible.
<source lang=apl>
⎕←M←2 2⍴3 4 4 5
3 4 4 5
⎕←R←⌹M
¯5 4
4 ¯3 R+.×M
1 0 0 1
⌹2 2⍴0
DOMAIN ERROR
⌹2 2⍴0 ∧
</syntaxhighlight>
When the argument is a scalar or vector, or the given matrix has more rows than columns (<source lang=apl inline>r>c</syntaxhighlight> where <source lang=apl inline>r c≡⍴X</syntaxhighlight>), Matrix Inverse computes specific forms of generalized inverse called Moore-Penrose inverse. For a scalar, the result is the reciprocal of the argument; for a vector, the result equals <source lang=apl inline>(+X)÷X+.×+X</syntaxhighlight>. For a non-square matrix, the result equals <source lang=apl inline>(+⍉X)⌹(+⍉X)+.×X</syntaxhighlight> (where <source lang=apl inline>+⍉X</syntaxhighlight> is the conjugate transpose of X).
<source lang=apl>
(⌹2)(⌹2J1)
0.5 0.4J¯0.2
÷2 2J1
0.5 0.4J¯0.2
(⌹3 1)(⌹2 1 1J2)
┌───────┬────────────────┐ │0.3 0.1│0.2 0.1 0.1J¯0.2│ └───────┴────────────────┘
{(+⍵)÷⍵+.×+⍵}¨ (3 1) (2 1 1J2)
┌───────┬────────────────┐ │0.3 0.1│0.2 0.1 0.1J¯0.2│ └───────┴────────────────┘
(⌹3 1)(⌹2 1 1J2) +.ר (3 1)(2 1 1J2)
1 1
⎕←M←3 2⍴1 ¯1 0J1 1 ¯1 0J1 1 ¯1 0J1 1
¯1 0J1
⎕←R←⌹M 0.5J¯0.5 0.25J¯0.25 ¯0.25J¯0.25
¯0.5J¯0.5 0.25J¯0.25 ¯0.25J¯0.25
R≡{(+⍉⍵)⌹(+⍉⍵)+.×⍵} M
1
R+.×M 1.0000E000J¯5.5511E¯17 0
¯2.7756E¯17J05.5511E¯17 1 </syntaxhighlight>
External links
Lesson
Documentation
- Dyalog
- APLX
- NARS2000
- J Dictionary, NuVoc (as <source lang=j inline>%.</syntaxhighlight>)