One Hat Cyber Team
Your IP :
216.73.216.80
Server IP :
194.44.31.54
Server :
Linux zen.imath.kiev.ua 4.18.0-553.77.1.el8_10.x86_64 #1 SMP Fri Oct 3 14:30:23 UTC 2025 x86_64
Server Software :
Apache/2.4.37 (Rocky Linux) OpenSSL/1.1.1k
PHP Version :
5.6.40
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
usr
/
share
/
doc
/
Macaulay2
/
Macaulay2Doc
/
html
/
View File Name :
_solve.html
<!DOCTYPE html> <html lang="en"> <head> <title>solve -- solve linear equation(s)</title> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <link type="text/css" rel="stylesheet" href="../../../../Macaulay2/Style/doc.css"> <link rel="stylesheet" href="../../../../Macaulay2/Style/katex/katex.min.css"> <script defer="defer" src="../../../../Macaulay2/Style/katex/katex.min.js"></script> <script defer="defer" src="../../../../Macaulay2/Style/katex/contrib/auto-render.min.js"></script> <script> var macros = { "\\break": "\\\\", "\\ZZ": "\\mathbb{Z}", "\\NN": "\\mathbb{N}", "\\QQ": "\\mathbb{Q}", "\\RR": "\\mathbb{R}", "\\CC": "\\mathbb{C}", "\\PP": "\\mathbb{P}" }, delimiters = [ { left: "$$", right: "$$", display: true}, { left: "\\[", right: "\\]", display: true}, { left: "$", right: "$", display: false}, { left: "\\(", right: "\\)", display: false} ], ignoredTags = [ "kbd", "var", "samp", "script", "noscript", "style", "textarea", "pre", "code", "option" ]; document.addEventListener("DOMContentLoaded", function() { renderMathInElement(document.body, { delimiters: delimiters, macros: macros, ignoredTags: ignoredTags, trust: true }); }); </script> <style>.katex { font-size: 1em; }</style> <script defer="defer" src="../../../../Macaulay2/Style/katex/contrib/copy-tex.min.js"></script> <script defer="defer" src="../../../../Macaulay2/Style/katex/contrib/render-a11y-string.min.js"></script> <script src="../../../../Macaulay2/Style/prism.js"></script> <script>var current_version = '1.25.06';</script> <script src="../../../../Macaulay2/Style/version-select.js"></script> <link type="image/x-icon" rel="icon" href="../../../../Macaulay2/Style/icon.gif"> </head> <body> <div id="buttons"> <div> <a href="https://macaulay2.com/">Macaulay2</a> <span id="version-select-container"></span> » <a title="Macaulay2 documentation" href="index.html">Documentation </a> <br><a href="_packages_spprovided_spwith_sp__Macaulay2.html">Packages</a> » <span><a title="Macaulay2 documentation" href="index.html">Macaulay2Doc</a> » <a href="_matrices.html">matrices</a> » <a title="the class of all matrices" href="___Matrix.html">Matrix</a> » <a title="solve linear equation(s)" href="_solve.html">solve</a></span> </div> <div class="right"> <form method="get" action="https://www.google.com/search"> <input placeholder="Search" type="text" name="q" value=""> <input type="hidden" name="q" value="site:macaulay2.com/doc"> </form> <a href="_divide__By__Variable.html">next</a> | <a href="_select__In__Subring.html">previous</a> | <a href="_divide__By__Variable.html">forward</a> | <a href="_select__In__Subring.html">backward</a> | <a href="___Matrix.html">up</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> </div> </div> <hr> <div> <h1>solve -- solve linear equation(s)</h1> <ul> <li> <dl class="element"> <dt>Usage: </dt> <dd><code class="language-macaulay2">X = solve(A,B)</code></dd> </dl> </li> <li>Inputs: <ul> <li><span><span class="tt">A</span>, <span>a <a title="the class of all matrices" href="___Matrix.html">matrix</a></span>, or <span>a <a title="the class of all mutable matrices" href="___Mutable__Matrix.html">mutable matrix</a></span>, of size m by n over a field R, which can be one of: ZZ/p, GF(p^n), QQ, RR, CC</span></li> <li><span><span class="tt">B</span>, of the same type of matrix as <span class="tt">A</span>, over the same ring, of size m by r</span></li> </ul> </li> <li><a href="_using_spfunctions_spwith_spoptional_spinputs.html">Optional inputs</a>: <ul> <li><span><span class="tt">ClosestFit</span><span class="tt"> => </span><span>a <a title="the class of boolean values" href="___Boolean.html">Boolean value</a></span>, <span>default value false</span>, whether to use the least squares method, in the case when the ring is <span class="tt">RR</span> or <span class="tt">CC</span></span></li> <li><span><span class="tt">MaximalRank</span><span class="tt"> => </span><span>a <a title="the class of boolean values" href="___Boolean.html">Boolean value</a></span>, <span>default value false</span>, declares to the system that the matrix is full rank. In some cases, this can dramatically speed up the computation. If the matrix is not full rank, then the results are potentially meaningless.</span></li> <li><span><span class="tt">Invertible</span><span class="tt"> => </span><span class="tt">...</span>, <span>default value false</span></span></li> <li><span><span class="tt">Precision</span><span class="tt"> => </span><span class="tt">...</span>, <span>default value 0</span></span></li> </ul> </li> <li>Outputs: <ul> <li><span><span class="tt">X</span>, of the same type of matrix as <span class="tt">A</span>, over the same ring, such that $AX=B$</span></li> </ul> </li> </ul> <div> <h2>Description</h2> <table class="examples"> <tr> <td> <pre><code class="language-macaulay2">i1 : kk = ZZ/101;</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">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 <-- kk</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i3 : b = matrix"1;1;1" ** kk o3 = | 1 | | 1 | | 1 | 3 1 o3 : Matrix kk <-- kk</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i4 : x = solve(A,b) o4 = | 2 | | -1 | | 34 | | 0 | 4 1 o4 : Matrix kk <-- kk</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i5 : A*x-b o5 = 0 3 1 o5 : Matrix kk <-- kk</code></pre> </td> </tr> </table> <table class="examples"> <tr> <td> <pre><code class="language-macaulay2">i6 : kk = GF(25) o6 = kk o6 : GaloisField</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i7 : a = kk_0 o7 = a o7 : kk</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i8 : A = matrix"a,a+1,a+2,3a,4;a-1,1,2a,6,10;19,7,a,11,13" ** kk o8 = | a a+1 a+2 -2a -1 | | a-1 1 2a 1 0 | | -1 2 a 1 -2 | 3 5 o8 : Matrix kk <-- kk</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i9 : b = matrix"1;-a+1;1" ** kk o9 = | 1 | | -a+1 | | 1 | 3 1 o9 : Matrix kk <-- kk</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i10 : x = solve(A,b) o10 = | -a | | -2a+1 | | -2a | | 0 | | 0 | 5 1 o10 : Matrix kk <-- kk</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i11 : A*x-b o11 = 0 3 1 o11 : Matrix kk <-- kk</code></pre> </td> </tr> </table> <table class="examples"> <tr> <td> <pre><code class="language-macaulay2">i12 : kk = QQ o12 = QQ o12 : Ring</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i13 : A = matrix"1,2,3,4;1,3,6,10;19,7,11,13" ** kk o13 = | 1 2 3 4 | | 1 3 6 10 | | 19 7 11 13 | 3 4 o13 : Matrix QQ <-- QQ</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i14 : b = matrix"1;1;1" ** kk o14 = | 1 | | 1 | | 1 | 3 1 o14 : Matrix QQ <-- QQ</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i15 : x = solve(A,b) o15 = | -7/47 | | 54/47 | | -18/47 | | 0 | 4 1 o15 : Matrix QQ <-- QQ</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i16 : A*x-b o16 = 0 3 1 o16 : Matrix QQ <-- QQ</code></pre> </td> </tr> </table> <div> <p></p> <p>Over <span class="tt">RR_{53}</span> or <span class="tt">CC_{53}</span>, if the matrix A is non-singular and square, then highly optimized LAPACK routines will be called.</p> <p></p> </div> <table class="examples"> <tr> <td> <pre><code class="language-macaulay2">i17 : printingPrecision = 4;</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i18 : A = matrix "1,2,3;1,3,6;19,7,11" ** RR o18 = | 1 2 3 | | 1 3 6 | | 19 7 11 | 3 3 o18 : Matrix RR <-- RR 53 53</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i19 : b = matrix "1;1;1" ** RR o19 = | 1 | | 1 | | 1 | 3 1 o19 : Matrix RR <-- RR 53 53</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i20 : x = solve(A,b) o20 = | -.1489 | | 1.149 | | -.383 | 3 1 o20 : Matrix RR <-- RR 53 53</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i21 : A*x-b o21 = | 2.22e-16 | | -2.22e-16 | | 0 | 3 1 o21 : Matrix RR <-- RR 53 53</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i22 : norm oo o22 = 2.220446049250313e-16 o22 : RR (of precision 53)</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i23 : clean(1e-15, A*x-b) o23 = 0 3 1 o23 : Matrix RR <-- RR 53 53</code></pre> </td> </tr> </table> <div> <p></p> <p>If you know that your matrix is square, and invertible, then providing the hint: MaximalRank=>true allows Macaulay2 to choose the fastest routines. For small matrix sizes, it should not be too noticeable, but for large matrices, the difference in time taken can be dramatic.</p> <p></p> </div> <table class="examples"> <tr> <td> <pre><code class="language-macaulay2">i24 : printingPrecision = 4;</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i25 : N = 40 o25 = 40</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i26 : A = mutableMatrix(CC_53, N, N); fillMatrix A;</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i28 : B = mutableMatrix(CC_53, N, 2); fillMatrix B;</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i30 : time X = solve(A,B); -- used 9.9957e-05s (cpu); 9.6871e-05s (thread); 0s (gc)</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i31 : time X = solve(A,B, MaximalRank=>true); -- used 8.7554e-05s (cpu); 8.7644e-05s (thread); 0s (gc)</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i32 : norm(A*X-B) o32 = 5.111850690840453e-15 o32 : RR (of precision 53)</code></pre> </td> </tr> </table> <div> <p></p> <p>Over higher precision RR or CC, these routines will be much slower than the lower precision LAPACK routines.</p> <p></p> </div> <table class="examples"> <tr> <td> <pre><code class="language-macaulay2">i33 : N = 100 o33 = 100</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i34 : A = mutableMatrix(CC_100, N, N); fillMatrix A;</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i36 : B = mutableMatrix(CC_100, N, 2); fillMatrix B;</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i38 : time X = solve(A,B); -- used 0.0940842s (cpu); 0.0940823s (thread); 0s (gc)</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i39 : time X = solve(A,B, MaximalRank=>true); -- used 0.0941468s (cpu); 0.0941473s (thread); 0s (gc)</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i40 : norm(A*X-B) o40 = 1.491578274689709814082355885932e-28 o40 : RR (of precision 100)</code></pre> </td> </tr> </table> <div> <p></p> <p>Giving the option ClosestFit=>true, in the case when the field is RR or CC, uses a least squares algorithm to find a best fit solution.</p> <p></p> </div> <table class="examples"> <tr> <td> <pre><code class="language-macaulay2">i41 : kk = RR_53;</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i42 : A = matrix"1,2,3,4;1,3,6,10;19,7,11,13" ** kk o42 = | 1 2 3 4 | | 1 3 6 10 | | 19 7 11 13 | 3 4 o42 : Matrix RR <-- RR 53 53</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i43 : b = matrix"1;1;1" ** kk o43 = | 1 | | 1 | | 1 | 3 1 o43 : Matrix RR <-- RR 53 53</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i44 : x1 = solve(A,b, ClosestFit=>true) o44 = | -.1899 | | .6399 | | .3367 | | -.275 | 4 1 o44 : Matrix RR <-- RR 53 53</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i45 : A*x1-b o45 = | -9.992e-16 | | -2.554e-15 | | -4.885e-15 | 3 1 o45 : Matrix RR <-- RR 53 53</code></pre> </td> </tr> </table> <div> <p></p> <p>Giving both options ClosestFit and MaximalRank allows Macaulay2 to call a faster algorithm.</p> <p></p> </div> <table class="examples"> <tr> <td> <pre><code class="language-macaulay2">i46 : x2 = solve(A,b, ClosestFit=>true, MaximalRank=>true) o46 = | -.1899 | | .6399 | | .3367 | | -.275 | 4 1 o46 : Matrix RR <-- RR 53 53</code></pre> </td> </tr> <tr> <td> <pre><code class="language-macaulay2">i47 : A*x2-b o47 = | 0 | | 0 | | 3.553e-15 | 3 1 o47 : Matrix RR <-- RR 53 53</code></pre> </td> </tr> </table> </div> <div> <h2>Caveat</h2> <div> <p>(1) This function is limited in scope, but has been designed to be much faster than generic algorithms. (2) If the matrix is a square invertible matrix, giving the option MaximalRank=>true can strongly speed up the computation. (3) For mutable matrices, this function is only currently implemented for densely encoded matrices.</p> </div> </div> <div> <h2>See also</h2> <ul> <li><span><a title="compute the LU decomposition of a matrix" href="___L__Udecomposition.html">LUdecomposition</a> -- compute the LU decomposition of a matrix</span></li> <li><span><a title="compute the inverse" href="_inverse.html">inverse</a> -- compute the inverse</span></li> <li><span><a title="determinant of a matrix" href="_determinant.html">determinant</a> -- determinant of a matrix</span></li> <li><span><a title="singular value decomposition of a matrix" href="___S__V__D.html">SVD</a> -- singular value decomposition of a matrix</span></li> <li><span><a href="_norm.html">norm</a></span></li> <li><span><a title="set to zero elements that are approximately zero" href="_clean.html">clean</a> -- set to zero elements that are approximately zero</span></li> </ul> </div> <div> <div class="waystouse"> <h2>Ways to use <span class="tt">solve</span>:</h2> <ul> <li><kbd>solve(Matrix,Matrix)</kbd></li> <li><kbd>solve(MutableMatrix,MutableMatrix)</kbd></li> <li><span><span class="tt">solve(Matrix,Vector)</span> (missing documentation)<!--tag: (solve,Matrix,Vector)--> </span></li> </ul> </div> <div class="waystouse"> <h2>For the programmer</h2> <p>The object <a title="solve linear equation(s)" href="_solve.html">solve</a> is <span>a <a title="a type of method function" href="___Method__Function__With__Options.html">method function with options</a></span>.</p> </div> <hr> <div class="waystouse"> <p>The source of this document is in <span class="tt">Macaulay2Doc/functions/solve-doc.m2:122:0</span>.</p> </div> </div> </div> </body> </html>