使用python为非平方矩阵A求解Ax

使用python为非平方矩阵A求解Ax

本文介绍了使用python为非平方矩阵A求解Ax = b的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我关注的特殊情况是A是一个n x d矩阵(其中k numpy随附的工具,但是它们仅适用于平方矩阵.我可以用一些线性独立的矢量填充矩阵,然后对其求平方",然后求解,但是我无法弄清楚如何选择这些矢量,以使它们与基本矢量线性无关,而且我认为这是不是唯一的方法,而我缺少可以使此操作变得更容易的方法.确实有比我提到的方法更简单的方法吗?如果不是,我的确如何选择将A完成的向量变成方矩阵?

I'm focusing on the special case where A is a n x d matrix (where k < d) representing an orthogonal basis for a subspace of R^d and b is known to be inside the subspace.I thought of using the tools provided with numpy, however they only work with square matrices. I had the approach of filling in the matrix with some linearly independent vectors to "square" it and then solve, but I could not figure out how to choose those vectors so that they will be linearly independent of the basis vectors, plus I think it's not the only approach and I'm missing something that can make this easier.is there indeed a simpler approach than the one I mentioned? if not, how indeed do I choose those vectors that would complete Ainto a square matrix?

推荐答案

正如您提到的, np.linalg.solve 需要一个完整的方阵.

As you mentioned, np.linalg.solve needs a full-rank square matrix.

对于所有其他线性情况,如果您对min||Ax-b||^2.感兴趣(您可能对),则可以使用 np.linalg.lstsq .

For all the other linear cases, if you are interested in min||Ax-b||^2. (you probably are) you can use np.linalg.lstsq.

方程可能是欠定的,确定的或过度确定的(即a的线性独立行的数量可以小于,等于或大于其线性数量)独立的列).如果a是正方形且具有全秩,则x(但针对四舍五入误差)是方程的精确"解.

The equation may be under-, well-, or over- determined (i.e., the number of linearly independent rows of a can be less than, equal to, or greater than its number of linearly independent columns). If a is square and of full rank, then x (but for round-off error) is the "exact" solution of the equation.

(我的粗体注释)

原始np.linalg.solve的文档中也提到了这一点:

This is also mentioned in the docs of the original np.linalg.solve:

这篇关于使用python为非平方矩阵A求解Ax = b的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 07:55