<p><a href="http://www.mathworks.com/help/matlab/ref/mrdivide.html" rel="noreferrer">MRDIVIDE</a>或<code>/</code>运算符实际上解决了<code>xb = a</code>线性系统,而不是求解系统<code>bx = a</code>的{a2}或{<cd3>}运算符。在</p>
<p>要求解具有非对称、不可逆矩阵<code>b</code>的系统<code>b</code>,您可以依赖<code>mridivide()</code>,这是通过高斯消去的{<cd6>}的因式分解来完成的,或者是通过奇异值分解和(默认)公差水平以下的奇异值的零化来完成的<code>pinv()</code>。在</p>
<p>这是区别(对于<code>mldivide</code>的情况):<a href="https://www.mathworks.com/support/solutions/en/data/1-3TPS3Y/index.html?product=ML&solution=1-3TPS3Y" rel="noreferrer">What is the difference between PINV and MLDIVIDE when I solve A*x=b?</a></p>
<blockquote>
<p>When the system is overdetermined, both algorithms provide the
same answer. When the system is underdetermined, PINV will return the
solution x, that has the minimum norm (min NORM(x)). MLDIVIDE will
pick the solution with least number of non-zero elements.</p>
</blockquote>
<p>在您的例子中:</p>
<pre><code>% solve xb = a
a = [1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9];
b = ones(25, 18);
</code></pre>
<p>该系统尚未确定,两种不同的解决方案将是:</p>
^{pr2}$
<p>在这两种情况下,<code>xb-a</code>的近似误差是不可忽略的(非精确解),并且相同,即<code>norm(x1*b-a)</code>和{<cd13>}将返回相同的结果。在</p>
<p>MATLAB在做什么?</strong></p>
<p>这篇文章在<a href="https://scicomp.stackexchange.com/a/1004/4014">scicomp.stackexchange.com</a>中给出了由“\”运算符调用的算法(以及对属性的检查),这取决于矩阵<code>b</code>的结构。我假设类似的选项也适用于<code>/</code>运算符。在</p>
<p>例如,MATLAB很可能正在进行高斯消去,给出无穷远处最稀疏的解(这就是5的来源)。在</p>
<p><strong>Python在做什么?</strong></p>
<p>Python在<code>linalg.lstsq</code>中使用伪逆/SVD,如上所示(这就是为什么得到的向量为0.2)。实际上,以下两种方法都会得到与MATLAB的<code>pinv()</code>相同的结果:</p>
<pre><code>from numpy import *
a = array([1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9])
b = ones((25, 18))
# xb = a: solve b.T x.T = a.T instead
x2 = linalg.lstsq(b.T, a.T)[0]
x2 = dot(a, linalg.pinv(b))
</code></pre>