Next: , Previous: Matrix Parts, Up: Matrices and Tensors


4.3 Matrix commands

— Command: transpose matrix

Computes the transpose of (matrix).

— Command: determinant matrix

The Jacal command determinant computes the determinant of a square matrix. Attempting to take the determinant of a non-square matrix will produce an error message.

          e1 : a:[[1,2],[6,7]];
          
              [1  2]
          e1: [    ]
              [6  7]
          
          e2 : determinant(a);
          
          e2: -5
— Command: charpoly matrix var

The characteristic polynomial of matrix:

determinant(matrix - I var)

— Command: . matrix1 matrix2

Matrix multiplication.

          e1 : a:[[1, 2, 3], [5, 2, 7]];
          
              [1  2  3]
          e1: [       ]
              [5  2  7]
          
          e2 : b:[[3, 2], [6, 4]];
          
              [3  2]
          e2: [    ]
              [6  4]
          
          e3 : b . a;
          
              [13  10  23]
          e3: [          ]
              [26  20  46]
— Command: ^^ matrix exponent

The infix operator ^^ is used for raising a square matrix to an integral power.

          e8 : a:[[1, 0], [-1, 1]];
          
              [1   0]
          e8: [     ]
              [-1  1]
          
          e9 : a^^3;
          
              [1   0]
          e9: [     ]
              [-3  1]

Negative exponents raise the inverse matrix to a power.

          e8 : [[a, b], [c, d]];
          
              [a  b]
          e8: [    ]
              [c  d]
          
          e9 : e8^^-1;
          
              [     d           - b    ]
              [-----------  -----------]
              [- b c + a d  - b c + a d]
              [                        ]
          e9: [    - c           a     ]
              [-----------  -----------]
              [- b c + a d  - b c + a d]
          
          e10 : e8^^-2;
          
               [               2                  - a b - b d       ]
               [        b c + d            -------------------------]
               [-------------------------   2  2                2  2]
               [ 2  2                2  2  b  c  - 2 a b c d + a  d ]
               [b  c  - 2 a b c d + a  d                            ]
               [                                    2               ]
          e10: [       - a c - c d                 a  + b c         ]
               [-------------------------  -------------------------]
               [ 2  2                2  2   2  2                2  2]
               [b  c  - 2 a b c d + a  d   b  c  - 2 a b c d + a  d ]
          
          e11 : e8 . e9;
          
               [1  0]
          e11: [    ]
               [0  1]
          
          e12 : e9 . e8;
          
               [1  0]
          e12: [    ]
               [0  1]
          
          e13 : e10 . e8 . e8;
          
               [1  0]
          e13: [    ]
               [0  1]
— Command: dotproduct vector_1 vector_2

The Jacal function dotproduct returns the dot product of two row vectors of the same length. It will also give the dot product of two matrices of the same size by computing the sum of the dot products of the corresponding rows or, what is the same, the trace of one matrix times the transpose of the other one.

          e28 : a:[1,2,3]; b:[3,1,5];
          
          e28: [1, 2, 3]
          
          e29 :
          e29: [3, 1, 5]
          
          e30 : dotproduct(a,b);
          
          e30: 20
— Command: crossproduct vector_1 vector_2

The Jacal command crossproduct computes the cross product of two vectors. By definition, the two vectors must each have three components.

          e24: [2 x, y + 2 x y ]
          
          e25 : crossproduct([1,2,3],[4,2,5]);
          
          e25: [4, 7, -6]