Matrix Inverse: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(links)
m (Text replacement - "<source" to "<syntaxhighlight")
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Built-in|Matrix Inverse|⌹}} is a [[monadic]] [[primitive function]] that returns the [[wikipedia:matrix inverse|inverse]] of a [[simple]] [[numeric]] array of [[rank]] 2 or lower. Some dialects automatically apply it to rank-2 [[subarray]]s of higher rank [[argument]]s. It shares the [[glyph]] ''Quad Divide'' <source lang=apl inline>⌹</source> (often called ''Domino'') with the dyadic function [[Matrix Divide]].
{{Built-in|Matrix Inverse|⌹}} is a [[monadic]] [[primitive function]] that returns the [[wikipedia:matrix inverse|inverse]] of a [[simple]] [[numeric]] array of [[rank]] 2 or lower. Some dialects automatically apply it to rank-2 [[subarray]]s of higher-rank [[argument]]s. It shares the [[glyph]] ''Quad Divide'' <syntaxhighlight lang=apl inline>⌹</syntaxhighlight> (often called ''Domino'') with the dyadic function [[Matrix Divide]].


== Examples ==
== Examples ==
Line 5: Line 5:
Matrix Inverse computes the ordinary inverse if the [[argument]] is a square matrix. [[DOMAIN ERROR]] is raised if the given matrix is not invertible.
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>
<syntaxhighlight lang=apl>
       ⎕←M←2 2⍴3 4 4 5
       ⎕←M←2 2⍴3 4 4 5
3 4
3 4
Line 19: Line 19:
  ⌹2 2⍴0     
  ⌹2 2⍴0     
  ∧     
  ∧     
</source>
</syntaxhighlight>


When the argument is a [[scalar]] or [[vector]], or the given matrix has more rows than columns (<source lang=apl inline>r>c</source> where <source lang=apl inline>r c≡⍴X</source>), Matrix Inverse computes specific forms of generalized inverse called [[wikipedia:Moore-Penrose inverse|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</source>. For a non-square matrix, the result equals <source lang=apl inline>(+⍉X)⌹(+⍉X)+.×X</source> (where <source lang=apl inline>+⍉X</source> is the [[wikipedia:conjugate transpose|conjugate transpose]] of X).
When the argument is a [[scalar]] or [[vector]], or the given matrix has more rows than columns (<syntaxhighlight lang=apl inline>r>c</syntaxhighlight> where <syntaxhighlight lang=apl inline>r c≡⍴X</syntaxhighlight>), Matrix Inverse computes specific forms of generalized inverse called [[wikipedia:Moore-Penrose inverse|Moore-Penrose inverse]]. For a scalar, the result is the [[reciprocal]] of the argument; for a vector, the result equals <syntaxhighlight lang=apl inline>(+X)÷X+.×+X</syntaxhighlight>. For a non-square matrix, the result equals <syntaxhighlight lang=apl inline>(+⍉X)⌹(+⍉X)+.×X</syntaxhighlight> (where <syntaxhighlight lang=apl inline>+⍉X</syntaxhighlight> is the [[wikipedia:conjugate transpose|conjugate transpose]] of X).


<source lang=apl>
<syntaxhighlight lang=apl>
       (⌹2)(⌹2J1)
       (⌹2)(⌹2J1)
0.5 0.4J¯0.2
0.5 0.4J¯0.2
Line 52: Line 52:
  1.0000E000J¯5.5511E¯17 0
  1.0000E000J¯5.5511E¯17 0
¯2.7756E¯17J05.5511E¯17 1
¯2.7756E¯17J05.5511E¯17 1
</source>
</syntaxhighlight>


== External links ==
== External links ==
Line 62: Line 62:
=== Documentation ===
=== Documentation ===


* [http://help.dyalog.com/latest/#Language/Primitive%20Functions/Matrix%20Inverse.htm Dyalog]
* [https://help.dyalog.com/latest/#Language/Primitive%20Functions/Matrix%20Inverse.htm Dyalog]
* [http://microapl.com/apl_help/ch_020_020_270.htm APLX]
* [http://microapl.com/apl_help/ch_020_020_270.htm APLX]
* [http://wiki.nars2000.org/index.php/Matrix_Inverse/Divide NARS2000]
* [http://wiki.nars2000.org/index.php/Matrix_Inverse/Divide NARS2000]
* J [https://www.jsoftware.com/help/dictionary/d131.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/percentdot NuVoc] (as <source lang=j inline>%.</source>)
* J [https://www.jsoftware.com/help/dictionary/d131.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/percentdot NuVoc] (as <syntaxhighlight lang=j inline>%.</syntaxhighlight>)


{{APL built-ins}}[[Category:Primitive functions]]
{{APL built-ins}}[[Category:Primitive functions]]

Revision as of 21:16, 10 September 2022

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 (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.

      ⎕←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     
 ∧

When the argument is a scalar or vector, or the given matrix has more rows than columns (r>c where r c≡⍴X), 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 (+X)÷X+.×+X. For a non-square matrix, the result equals (+⍉X)⌹(+⍉X)+.×X (where +⍉X is the conjugate transpose of X).

      (⌹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

External links

Lesson

Documentation


APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)
Quad names Index originComparison toleranceMigration levelAtomic vector