Matrix

From NARS2000
Jump to: navigation, search
Z←f⌻R applies the monadic function f to the (square) diagonalizable matrix R as a whole and returns the resulting matrix. The shape of the result is ⍴R.
Z←L f⌻R applies the monadic derived function L∘f to the (square) diagonalizable matrix R as a whole and returns the resulting matrix. L is a scalar. The shape of the result is ⍴R.
Z←∘⌻R for Hypercomplex scalar R, returns a (square) matrix representation of R. The shape of the result is 2⍴=R.
Z←∘⌻R for a simple or nested vector R, returns a (square) diagonal matrix with the items in R inserted into the diagonal. For a nested vector R, its items must be simple numeric scalars, vectors, or matrices. The shape of the result is 2⍴+/≢¨R.
The symbol QuadJot (, U+233B) may be entered from the keyboard with Alt-'F' or Ctrl-'F' depending upon your keyboard layout.

When applying a scalar function to a matrix, the matrix is viewed as a container of its scalar elements and the scalar function is applied to the individual elements. Another way to look at this is as applying the scalar function to the matrix as a whole, that is treating it as a new datatype. This concept is identical to the Multisets operator which treats its arguments as a new datatype: Multisets, i.e., sets with repeated elements.

For example,

      ⍝ The Factorial of a matrix
      !⌻2 2⍴1 3 2 1
3.6274 8.8423
5.8949 3.6274
      m←0.01×3 3⍴⍳9
      m
0.01 0.02 0.03
0.04 0.05 0.06
0.07 0.08 0.09
      ⍝ The Sine of a matrix
      1○⌻m
0.0099221 0.019904 0.029886
0.039823  0.049783 0.059742
0.069724  0.079661 0.089599
      ⍝ Arcsin of Sine returns the argument
      ¯1○⌻1○⌻m
0.01 0.02 0.03
0.04 0.05 0.06
0.07 0.08 0.09


      ⍝ A matrix representation of a Quaternion
      ∘⌻<⍳4
1 ¯2 ¯3 ¯4
2  1 ¯4  3
3  4  1 ¯2
4 ¯3  2  1


      ⍝ A diagonal matrix
      ∘⌻⍳4
1 0 0 0
0 2 0 0
0 0 3 0
0 0 0 4
      ⍝ A block diagonal matrix
      ∘⌻(2 2⍴⍳4)⍬(3 3⍴⍳9)(10 20) 30
1 2 0 0 0  0  0  0
3 4 0 0 0  0  0  0
0 0 1 2 3  0  0  0
0 0 4 5 6  0  0  0
0 0 7 8 9  0  0  0
0 0 0 0 0 10  0  0
0 0 0 0 0  0 20  0
0 0 0 0 0  0  0 30

      ⍝ Factorial of a Complex number
      c←<⍳2
      ∘⌻c            ⍝ Matrix representation of a Complex number
1 ¯2
2  1
      !⌻∘⌻c          ⍝ Matrix Factorial of ...
0.11229 ¯0.32361
0.32361  0.11229
      1⌷[2]!⌻∘⌻c     ⍝ First column of ...
0.11229 0.32361 
      9○1⌷[2]!⌻∘⌻c   ⍝ Real parts of ...
0.11229 0.32361 
      <9○1⌷[2]!⌻∘⌻c  ⍝ Complex number whose coefficients are ...
0.11229J0.32361 
      !c             ⍝ Using a different algorithm (GSL Complex factorial)
0.11229J0.32361 

      ⍝ Factorial of a Quaternion
      q←<⍳4
      ∘⌻q            ⍝ Matrix representation of a Quaternion number
1 ¯2 ¯3 ¯4
2  1 ¯4  3
3  4  1 ¯2
4 ¯3  2  1
      !⌻∘⌻q          ⍝ Matrix Factorial of ...
 0.0060975  0.0010787  0.001618   0.0021573
¯0.0010787  0.0060975  0.0021573 ¯0.001618 
¯0.001618  ¯0.0021573  0.0060975  0.0010787
¯0.0021573  0.001618  ¯0.0010787  0.0060975
      1⌷[2]!⌻∘⌻q     ⍝ First column of ...
0.0060975 ¯0.0010787 ¯0.001618 ¯0.0021573 
      9○1⌷[2]!⌻∘⌻q   ⍝ Real parts of ...
0.0060975 ¯0.0010787 ¯0.001618 ¯0.0021573 
      <9○1⌷[2]!⌻∘⌻q  ⍝ Quaternion number whose coefficients are ...
0.0060975i¯0.0010787j¯0.001618k¯0.0021573 
      !q
0.0060975i¯0.0010787j¯0.001618k¯0.0021573