Sophie

Sophie

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

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>solve -- solve a linear equation</title>
<link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/>
</head>
<body>
<table class="buttons">
  <tr>
    <td><div><a href="_some__Terms.html">next</a> | <a href="_smith__Normal__Form_lp__Matrix_rp.html">previous</a> | <a href="_some__Terms.html">forward</a> | <a href="_smith__Normal__Form_lp__Matrix_rp.html">backward</a> | up | <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>
<hr/>
<div><h1>solve -- solve a linear equation</h1>
<div class="single"><h2>Synopsis</h2>
<ul><li><div class="list"><dl class="element"><dt class="heading">Usage: </dt><dd class="value"><div><tt>x = solve(A,b)</tt></div>
</dd></dl>
</div>
</li>
<li><div class="single">Inputs:<ul><li><span><tt>A</tt>, <span>a <a href="___Matrix.html">matrix</a></span>, or <span>a <a href="___Mutable__Matrix.html">mutable matrix</a></span> of size m by n over either a finite field ZZ/p, RR or CC</span></li>
<li><span><tt>b</tt>, the same type of matrix, over the same ring, of size m by r</span></li>
</ul>
</div>
</li>
<li><div class="single">Outputs:<ul><li><span><tt>x</tt>, the same type of matrix, over the same ring, of size n by r, such that <tt>Ax=b</tt></span></li>
</ul>
</div>
</li>
<li><div class="single"><a href="_using_spfunctions_spwith_spoptional_spinputs.html">Optional inputs</a>:<ul><li><span><tt>MaximalRank => </tt><span><span>an <a href="___Z__Z.html">integer</a></span>, </span></span></li>
<li><span><tt>ClosestFit => </tt><span><span>a <a href="___Boolean.html">Boolean value</a></span>, <span>default value false</span>, whether to use the least squares method</span></span></li>
<li><span><tt>MaximalRank => </tt><span><span>a <a href="___Boolean.html">Boolean value</a></span>, <span>default value false</span>, whether to assume the matrix has maximal rank, in case the least squares method is used</span></span></li>
</ul>
</div>
</li>
</ul>
</div>
<div class="single"><h2>Description</h2>
<div><p>(Disambiguation: for division of matrices, which can also be thought of as solving a system of linear equations, see instead <a href="___Matrix_sp_sl_sl_sp__Matrix.html" title="factor a map through another">Matrix // Matrix</a>.  For lifting a map between modules to a map between their free resolutions, see <a href="_extend.html" title="extend a module map to a chain map, if possible">extend</a>.)</p>
There are several restrictions.  The first is that there are only a limited number of rings for which this function is implemented.  Second, over <a href="___R__R.html" title="the class of all real numbers">RR</a> or <a href="___C__C.html" title="the class of all complex numbers">CC</a>, the matrix <tt>A</tt> must be a square non-singular matrix.  Third, if <tt>A</tt> and <tt>b</tt> are mutable matrices over <a href="___R__R.html" title="the class of all real numbers">RR</a> or <a href="___C__C.html" title="the class of all complex numbers">CC</a>, they must be dense matrices.<table class="examples"><tr><td><pre>i1 : kk = ZZ/101;</pre>
</td></tr>
<tr><td><pre>i2 : A = matrix"1,2,3,4;1,3,6,10;19,7,11,13" ** kk

o2 = | 1  2 3  4  |
     | 1  3 6  10 |
     | 19 7 11 13 |

              3        4
o2 : Matrix kk  &lt;--- kk</pre>
</td></tr>
<tr><td><pre>i3 : b = matrix"1;1;1" ** kk

o3 = | 1 |
     | 1 |
     | 1 |

              3        1
o3 : Matrix kk  &lt;--- kk</pre>
</td></tr>
<tr><td><pre>i4 : x = solve(A,b)

o4 = | 2  |
     | -1 |
     | 34 |
     | 0  |

              4        1
o4 : Matrix kk  &lt;--- kk</pre>
</td></tr>
<tr><td><pre>i5 : A*x-b

o5 = 0

              3        1
o5 : Matrix kk  &lt;--- kk</pre>
</td></tr>
</table>
Over <a href="___R__R.html" title="the class of all real numbers">RR</a> or <a href="___C__C.html" title="the class of all complex numbers">CC</a>, the matrix <tt>A</tt> must be a non-singular square matrix.<table class="examples"><tr><td><pre>i6 : printingPrecision = 2;</pre>
</td></tr>
<tr><td><pre>i7 : A = matrix "1,2,3;1,3,6;19,7,11" ** RR

o7 = | 1  2 3  |
     | 1  3 6  |
     | 19 7 11 |

                3          3
o7 : Matrix RR    &lt;--- RR
              53         53</pre>
</td></tr>
<tr><td><pre>i8 : b = matrix "1;1;1" ** RR

o8 = | 1 |
     | 1 |
     | 1 |

                3          1
o8 : Matrix RR    &lt;--- RR
              53         53</pre>
</td></tr>
<tr><td><pre>i9 : x = solve(A,b)

o9 = | -.15 |
     | 1.1  |
     | -.38 |

                3          1
o9 : Matrix RR    &lt;--- RR
              53         53</pre>
</td></tr>
<tr><td><pre>i10 : A*x-b

o10 = | 0        |
      | -3.3e-16 |
      | -8.9e-16 |

                 3          1
o10 : Matrix RR    &lt;--- RR
               53         53</pre>
</td></tr>
<tr><td><pre>i11 : norm oo

o11 = 8.88178419700125e-16

o11 : RR (of precision 53)</pre>
</td></tr>
</table>
For large dense matrices over <a href="___R__R.html" title="the class of all real numbers">RR</a> or <a href="___C__C.html" title="the class of all complex numbers">CC</a>, this function calls the lapack routines.<table class="examples"><tr><td><pre>i12 : n = 10;</pre>
</td></tr>
<tr><td><pre>i13 : A = random(CC^n,CC^n)

o13 = | .74+.97i .3+.84i  .33+.8i   .73+.77i .24+.38i .31+.99i .23+.59i
      | .86+.54i .38+.96i .12+.5i   .73+.14i .34+.83i .85+.63i .33+.7i 
      | .46+.47i .46+.48i .92+.09i  .63+.73i .58+.97i .46+.52i .42+.35i
      | .29+.96i .26      .49+.003i .29+.93i .28+.67i .86+.38i .81+.41i
      | .37+.78i .51+.92i .51+.84i  .46+.86i .28+.36i .23+.54i .91+.45i
      | .73+.09i .45+.3i  .59+.78i  .16+.72i .29+.56i .78+.63i .64+.67i
      | .2+.99i  .51+.43i .58+.66i  .02+.94i .39+.81i .15+.55i .88+.29i
      | .42+.8i  .9+.4i   .96+.02i  .38+.56i .24+.84i .95+.65i .26+.52i
      | .62+.52i .95+.35i .75+.46i  .9+.28i  .9+.39i  .48+.65i .63+.91i
      | .46+.51i .81+.39i .94+.89i  .2+.25i  .81i     .64+.09i .57+.26i
      -----------------------------------------------------------------------
      .68+.15i  .88+.7i  .58+.94i  |
      .63+.5i   .36+.25i .78+.38i  |
      .066+.12i .1+.32i  .46+.88i  |
      .92+.13i  .67+.74i .46+.73i  |
      .95+i     .03+.77i .61+.95i  |
      .46+.16i  .72+.21i .06+.49i  |
      .69+.66i  .02+.52i .43+.48i  |
      .16+.95i  .07+.65i .65+.72i  |
      .81+.08i  .37+.45i .23+.005i |
      .88+.61i  .11+.26i .27+.63i  |

                 10          10
o13 : Matrix CC     &lt;--- CC
               53          53</pre>
</td></tr>
<tr><td><pre>i14 : b = random(CC^n,CC^2)

o14 = | .6+.45i  .53+.81i  |
      | .32+.3i  .53+.36i  |
      | .02+.54i .076+.45i |
      | .54+.31i .47+.99i  |
      | .59+.17i .4+.71i   |
      | .64+.65i .47+.65i  |
      | .46+.2i  .72+.9i   |
      | .36+.91i .71+.41i  |
      | .22+.47i .74+.1i   |
      | .68+.49i .02+.53i  |

                 10          2
o14 : Matrix CC     &lt;--- CC
               53          53</pre>
</td></tr>
<tr><td><pre>i15 : x = solve(A,b)

o15 = | -.31-.19i  -.51-.82i |
      | -.43-.92i  -2.3-4.4i |
      | .91+.72i   3.8+2.3i  |
      | -.8+.55i   -1.2+.73i |
      | .76+.17i   .63+.21i  |
      | -.37+.087i -.62+.65i |
      | -.046+.24i .72+.59i  |
      | .64-1.2i   -.15-2i   |
      | 1.9+.89i   4-.23i    |
      | -.56-.17i  -1.7+3i   |

                 10          2
o15 : Matrix CC     &lt;--- CC
               53          53</pre>
</td></tr>
<tr><td><pre>i16 : norm ( matrix A * matrix x - matrix b )

o16 = 1.37327003955667e-15

o16 : RR (of precision 53)</pre>
</td></tr>
</table>
This may be used to invert a matrix over <tt>ZZ/p</tt>, <a href="___R__R.html" title="the class of all real numbers">RR</a> or <tt>QQ</tt>.<table class="examples"><tr><td><pre>i17 : A = random(RR^5, RR^5)

o17 = | .065 .23  .14 .99 .27 |
      | .49  .11  .58 .2  .16 |
      | .61  .56  .11 .84 .51 |
      | .74  .46  .29 .5  .81 |
      | .12  .083 .74 .41 1   |

                 5          5
o17 : Matrix RR    &lt;--- RR
               53         53</pre>
</td></tr>
<tr><td><pre>i18 : I = id_(target A)

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 RR    &lt;--- RR
               53         53</pre>
</td></tr>
<tr><td><pre>i19 : A' = solve(A,I)

o19 = | 2.5  .88  -5   5.1  -2.4 |
      | -6.7 -.46 12   -9.5 3.5  |
      | -1.9 1.3  3.4  -3.7 1.6  |
      | 2.5  .17  -2.4 1.8  -.95 |
      | .64  -1.1 -1.9 2.2  .18  |

                 5          5
o19 : Matrix RR    &lt;--- RR
               53         53</pre>
</td></tr>
<tr><td><pre>i20 : norm(A*A' - I)

o20 = 8.88178419700125e-16

o20 : RR (of precision 53)</pre>
</td></tr>
<tr><td><pre>i21 : norm(A'*A - I)

o21 = 2.1094237467878e-15

o21 : RR (of precision 53)</pre>
</td></tr>
</table>
Another method, which isn't generally as fast, and isn't as stable over <a href="___R__R.html" title="the class of all real numbers">RR</a> or <a href="___C__C.html" title="the class of all complex numbers">CC</a>, is to lift the matrix <tt>b</tt> along the matrix <tt>A</tt> (see <a href="___Matrix_sp_sl_sl_sp__Matrix.html" title="factor a map through another">Matrix // Matrix</a>).<table class="examples"><tr><td><pre>i22 : A'' = I // A

o22 = | 2.5  .88  -5   5.1  -2.4 |
      | -6.7 -.46 12   -9.5 3.5  |
      | -1.9 1.3  3.4  -3.7 1.6  |
      | 2.5  .17  -2.4 1.8  -.95 |
      | .64  -1.1 -1.9 2.2  .18  |

                 5          5
o22 : Matrix RR    &lt;--- RR
               53         53</pre>
</td></tr>
<tr><td><pre>i23 : norm(A' - A'')

o23 = 0

o23 : RR (of precision 53)</pre>
</td></tr>
</table>
</div>
</div>
<div class="single"><h2>Caveat</h2>
<div>This function is limited in scope, but is sometimes useful for very large matrices</div>
</div>
<div class="single"><h2>See also</h2>
<ul><li><span><a href="___L__Udecomposition.html" title="LU decomposition">LUdecomposition</a> -- LU decomposition</span></li>
<li><span><a href="___S__V__D.html" title="singular value decomposition of a matrix">SVD</a> -- singular value decomposition of a matrix</span></li>
<li><span><a href="___Mutable__Matrix.html" title="the class of all mutable matrices">MutableMatrix</a> -- the class of all mutable matrices</span></li>
<li><span><a href="_norm.html" title="">norm</a></span></li>
<li><span><a href="_random.html" title="get a random element">random</a> -- get a random element</span></li>
</ul>
</div>
<div class="waystouse"><h2>Ways to use <tt>solve</tt> :</h2>
<ul><li>solve(Matrix,Matrix)</li>
<li>solve(MutableMatrix,MutableMatrix)</li>
</ul>
</div>
</div>
</body>
</html>