[next][previous][up][top][index]
search for:

manipulating matrices

In previous sections we have learned various ways to make matrices. Now we discuss methods for manipulating matrices.

The principal way to extract a submatrix of a matrix is with submatrix.

i1 : R = ZZ/101[a .. o];
i2 : p = genericMatrix(R, a, 3, 5)

o2 = {0} | a d g j m |
     {0} | b e h k n |
     {0} | c f i l o |

             3       5
o2 : Matrix R  <--- R
i3 : submatrix(p,{1,2},{3,4})

o3 = {0} | k n |
     {0} | l o |

             2       2
o3 : Matrix R  <--- R

A subset of columns can be extracted with _ and a subset of the rows can be extracted with ^.

i4 : p^{1,2}

o4 = {0} | b e h k n |
     {0} | c f i l o |

             2       5
o4 : Matrix R  <--- R
i5 : p_{3,4}

o5 = {0} | j m |
     {0} | k n |
     {0} | l o |

             3       2
o5 : Matrix R  <--- R

Since ^ and _ have the same parsing precedence, and associate to the left by default, these operations can be combined without adding parentheses, giving a slower form of submatrix.

i6 : p^{1,2}_{3,4}

o6 = {0} | k n |
     {0} | l o |

             2       2
o6 : Matrix R  <--- R
i7 : p_{3,4}^{1,2}

o7 = {0} | k n |
     {0} | l o |

             2       2
o7 : Matrix R  <--- R

We can transpose a matrix.

i8 : transpose p

o8 = {-1} | a b c |
     {-1} | d e f |
     {-1} | g h i |
     {-1} | j k l |
     {-1} | m n o |

             5       3
o8 : Matrix R  <--- R

We can test whether a matrix, regarded as a linear transformation, is injective or surfective.

i9 : isSurjective p

o9 = false
i10 : isInjective p

o10 = false
i11 : isInjective transpose p

o11 = true

We can use diff to differentiate a matrix with respect to a variable and contract to contract.

i12 : q = matrix {{a^2,b^2,c^2},{a*b,b*c,a*c}}

o12 = {0} | a2 b2 c2 |
      {0} | ab bc ac |

              2       3
o12 : Matrix R  <--- R
i13 : diff(a,q)

o13 = {0} | 2a 0 0 |
      {0} | b  0 c |

              2       3
o13 : Matrix R  <--- R
i14 : contract(a,q)

o14 = {0} | a 0 0 |
      {0} | b 0 c |

              2       3
o14 : Matrix R  <--- R

These operations have a meaning when the first argument is itself a polynomial, or even a matrix of polynomials.

i15 : r = matrix{{1,a,a^2,a^3}}

o15 = {0} | 1 a a2 a3 |

              1       4
o15 : Matrix R  <--- R
i16 : diff(transpose r,r)

o16 = {0} | 1 a a2 a3  |
      {1} | 0 1 2a 3a2 |
      {2} | 0 0 2  6a  |
      {3} | 0 0 0  6   |

              4       4
o16 : Matrix R  <--- R
i17 : contract(transpose r,r)

o17 = {0} | 1 a a2 a3 |
      {1} | 0 1 a  a2 |
      {2} | 0 0 1  a  |
      {3} | 0 0 0  1  |

              4       4
o17 : Matrix R  <--- R

For more information about matrices, see Matrix.


[next][previous][up][top][index]
search for: