Matrix Divide

From APL Wiki
Revision as of 22:09, 10 September 2022 by Adám Brudzewsky (talk | contribs) (Text replacement - "</source>" to "</syntaxhighlight>")
Jump to navigation Jump to search

Matrix Divide () is a dyadic function that performs matrix division between two arguments of rank 2 or less. 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 monadic function Matrix Inverse.

Examples

The result of <source lang=apl inline>X⌹Y</syntaxhighlight> is equal to <source lang=apl inline>(⌹Y)+.×X</syntaxhighlight>, which is analogous to <source lang=apl inline>X÷Y</syntaxhighlight> being equal to <source lang=apl inline>(÷Y)×X</syntaxhighlight>. As a consequence, <source lang=apl inline>X≡Y+.×X⌹Y</syntaxhighlight> is true for square matrices.

<source lang=apl>

     ⎕←X←2 2⍴1 2 3 4

1 2 3 4

     ⎕←Y←2 2⍴5 6 7 8

5 6 7 8

     X⌹Y
5  4

¯4 ¯3

     (⌹Y)+.×X
5  4

¯4 ¯3

     X≡Y+.×X⌹Y

1 </syntaxhighlight>

Applications

From the properties of Moore-Penrose inverse (which Matrix Inverse uses), Matrix Divide can not only be used to solve a system of linear equations, but also to find the linear least squares solution to an overdetermined system.

The following example solves the system of equations . The answer is .

<source lang=apl>

     ⎕←X←2 2⍴1 2 2 ¯1

1 2 2 ¯1

     Y←5 8
     Y⌹X

4.2 0.4 </syntaxhighlight>

The following example solves the linear least squares over the five points . The answer is .

<source lang=apl>

     ⎕←X←1,⍪⍳5

1 1 1 2 1 3 1 4 1 5

     Y←5 1 4 2 8
     Y⌹X

1.9 0.7 </syntaxhighlight>

When used with real vectors as both arguments, <source lang=apl inline>Y×X⌹Y</syntaxhighlight> gives the projection of X onto a basis vector Y. The remaining component of X, namely <source lang=apl inline>R←X-Y×X⌹Y</syntaxhighlight>, is orthogonal to Y (<source lang=apl inline>R+.×Y</syntaxhighlight> is zero).

<source lang=apl>

     (X Y)←(2 7)(3 1)
     X⌹Y

1.3

     Y×X⌹Y  ⍝ Projection of X onto Y

3.9 1.3

     X-Y×X⌹Y  ⍝ The remaining component in X

¯1.9 5.7

     ⎕CT>|Y+.×X-Y×X⌹Y  ⍝ ∧ is orthogonal to Y (with negligible error)

1 </syntaxhighlight>

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