Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 7ebd25ac536d248d499a3ce2acda963a > files > 3811

Macaulay2-1.3.1-8.fc15.i686.rpm

<?xml version="1.0" encoding="utf-8" ?>  <!-- for emacs: -*- coding: utf-8 -*- -->
<!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"	 "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>Singular Book 2.1.6 -- matrix operations</title>
<link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/>
</head>
<body>
<table class="buttons">
  <tr>
    <td><div><a href="___Singular_sp__Book_sp2.1.7.html">next</a> | <a href="___Singular_sp__Book_sp1.8.20.html">previous</a> | <a href="___Singular_sp__Book_sp2.1.7.html">forward</a> | <a href="___Singular_sp__Book_sp1.8.20.html">backward</a> | <a href="___M2__Singular__Book.html">up</a> | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div>

    </td>
  </tr>
</table>
<div><a href="index.html" title="">Macaulay2Doc</a> > <a href="_basic_spcommutative_spalgebra.html" title="">basic commutative algebra</a> > <a href="___M2__Singular__Book.html" title="Macaulay2 examples for the Singular book">M2SingularBook</a> > <a href="___Singular_sp__Book_sp2.1.6.html" title="matrix operations">Singular Book 2.1.6</a></div>
<hr/>
<div><h1>Singular Book 2.1.6 -- matrix operations</h1>
<div>In Macaulay2, matrices are defined over a ring.  There are many ways to make a matrix, but the easiest is to use the <a href="_matrix.html" title="make a matrix">matrix</a> routine.<table class="examples"><tr><td><pre>i1 : A = QQ[x,y,z];</pre>
</td></tr>
<tr><td><pre>i2 : M = matrix{{1, x+y, z^2},
                {x, 0,   x*y*z}}

o2 = | 1 x+y z2  |
     | x 0   xyz |

             2       3
o2 : Matrix A  &lt;--- A</pre>
</td></tr>
<tr><td><pre>i3 : N = matrix(A, {{1,2,3},{4,5,6},{7,8,9}})

o3 = | 1 2 3 |
     | 4 5 6 |
     | 7 8 9 |

             3       3
o3 : Matrix A  &lt;--- A</pre>
</td></tr>
</table>
The usual matrix arithmetic operations work.<table class="examples"><tr><td><pre>i4 : M+M

o4 = | 2  2x+2y 2z2  |
     | 2x 0     2xyz |

             2       3
o4 : Matrix A  &lt;--- A</pre>
</td></tr>
<tr><td><pre>i5 : x*N

o5 = | x  2x 3x |
     | 4x 5x 6x |
     | 7x 8x 9x |

             3       3
o5 : Matrix A  &lt;--- A</pre>
</td></tr>
<tr><td><pre>i6 : M*N

o6 = | 7z2+4x+4y+1 8z2+5x+5y+2 9z2+6x+6y+3 |
     | 7xyz+x      8xyz+2x     9xyz+3x     |

             2       3
o6 : Matrix A  &lt;--- A</pre>
</td></tr>
<tr><td><pre>i7 : N^3

o7 = | 468  576  684  |
     | 1062 1305 1548 |
     | 1656 2034 2412 |

             3       3
o7 : Matrix A  &lt;--- A</pre>
</td></tr>
<tr><td><pre>i8 : ((x+y+z)*N)^3

o8 = | 468x3+1404x2y+1404xy2+
     | 1062x3+3186x2y+3186xy2
     | 1656x3+4968x2y+4968xy2
     ------------------------------------------------------------------------
     468y3+1404x2z+2808xyz+1404y2z+1404xz2+1404yz2+468z3   
     +1062y3+3186x2z+6372xyz+3186y2z+3186xz2+3186yz2+1062z3
     +1656y3+4968x2z+9936xyz+4968y2z+4968xz2+4968yz2+1656z3
     ------------------------------------------------------------------------
     576x3+1728x2y+1728xy2+576y3+1728x2z+3456xyz+1728y2z+1728xz2+1728yz2+576z
     1305x3+3915x2y+3915xy2+1305y3+3915x2z+7830xyz+3915y2z+3915xz2+3915yz2+13
     2034x3+6102x2y+6102xy2+2034y3+6102x2z+12204xyz+6102y2z+6102xz2+6102yz2+2
     ------------------------------------------------------------------------
     3     684x3+2052x2y+2052xy2+
     05z3  1548x3+4644x2y+4644xy2
     034z3 2412x3+7236x2y+7236xy2
     ------------------------------------------------------------------------
     684y3+2052x2z+4104xyz+2052y2z+2052xz2+2052yz2+684z3     |
     +1548y3+4644x2z+9288xyz+4644y2z+4644xz2+4644yz2+1548z3  |
     +2412y3+7236x2z+14472xyz+7236y2z+7236xz2+7236yz2+2412z3 |

             3       3
o8 : Matrix A  &lt;--- A</pre>
</td></tr>
</table>
Indices in Macaulay2 are always 0 based, so the upper left entry is (0,0).  Indexing is performed using <a href="__us.html" title="a binary operator, used for subscripting and access to elements">_</a>.<table class="examples"><tr><td><pre>i9 : M_(1,2)

o9 = x*y*z

o9 : A</pre>
</td></tr>
</table>
Matrices cannot be modified.  Make a MutableMatrix if you want to modify a matrix.<table class="examples"><tr><td><pre>i10 : M1 = mutableMatrix M

o10 = | 1 x+y z2  |
      | x .   xyz |

o10 : MutableMatrix</pre>
</td></tr>
<tr><td><pre>i11 : M1_(1,2) = 37_A

o11 = 37

o11 : A</pre>
</td></tr>
<tr><td><pre>i12 : M1

o12 = | 1 x+y z2 |
      | x .   37 |

o12 : MutableMatrix</pre>
</td></tr>
<tr><td><pre>i13 : matrix M1

o13 = | 1 x+y z2 |
      | x 0   37 |

              2       3
o13 : Matrix A  &lt;--- A</pre>
</td></tr>
</table>
Matrices can be concatenated, either horizontally or vertically.  The number of rows must match for horizontal concatenation, and the number of columns must match for vertical concatenation.<table class="examples"><tr><td><pre>i14 : M | M

o14 = | 1 x+y z2  1 x+y z2  |
      | x 0   xyz x 0   xyz |

              2       6
o14 : Matrix A  &lt;--- A</pre>
</td></tr>
<tr><td><pre>i15 : M || N

o15 = | 1 x+y z2  |
      | x 0   xyz |
      | 1 2   3   |
      | 4 5   6   |
      | 7 8   9   |

              5       3
o15 : Matrix A  &lt;--- A</pre>
</td></tr>
</table>
Use <a href="_ideal_lp__Matrix_rp.html" title="make an ideal">ideal(Matrix)</a> to obtain the ideal generated by the entries of a matrix.<table class="examples"><tr><td><pre>i16 : ideal M

                              2
o16 = ideal (1, x, x + y, 0, z , x*y*z)

o16 : Ideal of A</pre>
</td></tr>
</table>
The <i>n</i> by <i>n</i> identity matrix is the identity map of the freemodule <i>A<sup>n</sup></i>.<table class="examples"><tr><td><pre>i17 : F = A^5

       5
o17 = A

o17 : A-module, free</pre>
</td></tr>
<tr><td><pre>i18 : id_(A^5)

o18 = | 1 0 0 0 0 |
      | 0 1 0 0 0 |
      | 0 0 1 0 0 |
      | 0 0 0 1 0 |
      | 0 0 0 0 1 |

              5       5
o18 : Matrix A  &lt;--- A</pre>
</td></tr>
</table>
In Macaulay2, integer matrices are just matrices defined over the ring of integers ZZ.<table class="examples"><tr><td><pre>i19 : matrix{{1,2,3},{4,5,6}}

o19 = | 1 2 3 |
      | 4 5 6 |

               2        3
o19 : Matrix ZZ  &lt;--- ZZ</pre>
</td></tr>
</table>
</div>
<div class="single"><h2>See also</h2>
<ul><li><span><a href="_matrices.html" title="">matrices</a></span></li>
</ul>
</div>
</div>
</body>
</html>