在opencv中是否有求解xA=b的函数?

在opencv中是否有求解xA=b的函数?,opencv,computer-vision,linear-regression,Opencv,Computer Vision,Linear Regression,我知道函数solve可以求解Ax=b。但是我想要一个函数来解x的xA=b? 有一些功能可用吗 顺便说一下,它应该像Matlab一样工作: x = B/A solves the system of linear equations x*A = B for x. The matrices A and B must contain the same number of columns. MATLAB® displays a warning message if A is badly scaled or

我知道函数
solve
可以求解
Ax=b
。但是我想要一个函数来解x的xA=b? 有一些功能可用吗

顺便说一下,它应该像Matlab一样工作:

x = B/A solves the system of linear equations x*A = B for x. The matrices A and B must contain the same number of columns. MATLAB® displays a warning message if A is badly scaled or nearly singular, but performs the calculation regardless.

If A is a scalar, then B/A is equivalent to B./A.

If A is a square n-by-n matrix and B is a matrix with n columns, then x = B/A is a solution to the equation x*A = B, if it exists.

If A is a rectangular m-by-n matrix with m ~= n, and B is a matrix with n columns, then x = B/A returns a least-squares solution of the system of equations x*A = B.

使用矩阵求逆的方法:

如果xA=b,那么x*A*inv(A)=b*inv(A)x=b*inv(A),那么在opencv中您将有:

void mrdivide(const cv::Mat &A, const cv::Mat &b, cv::Mat &x) {
    x = b * A.inv();
}
然而,由于矩阵求逆的成本较高,并且从数值方法的角度来看,精度损失较大,因此不建议这样做。此外,它只能解非超定线性方程组,且系统矩阵A必须是可逆的

使用矩阵转置的方法:

因为我们有xA=b,所以(xA)^T=b^ta^T*x^T=b^T,所以我们可以使用cv::solve(A.T(),b.T(),x),x.T()是一个结果:

void mrdivide(const cv::Mat &A, const cv::Mat &b, cv::Mat &x) {
     cv::solve(A.t(), b.t(), x);
     cv::transpose(x,x);
}

这是一般性的建议解决方案。它提供solve()所能提供的所有功能

为什么不直接将A和B的转置使用solve?但如果A不可逆(单极化),那么它就会失败。基于转置的解决方案比基于逆的解决方案要好得多。首先,矩阵求逆比求解方程组更复杂。第二,反演的数值稳定性不是很好。在C++中,行X.T-()不做任何事情。它应该是转置(x,x);或x=x.t()@你是对的,改变了答案。谢谢