首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在opencv中有用于求解xA=b的函数吗?

在opencv中有用于求解xA=b的函数吗?
EN

Stack Overflow用户
提问于 2014-05-20 02:09:42
回答 1查看 6.2K关注 0票数 4

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

顺便说一句,它应该像Matlab的分水岭那样工作:

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-20 07:12:14

基于矩阵求逆的方法:

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

代码语言:javascript
复制
void mrdivide(const cv::Mat &A, const cv::Mat &b, cv::Mat &x) {
    x = b * A.inv();
}

但是,由于矩阵反演的成本很高,从数值方法的角度来看,这是不可取的。此外,它只能解不超定义的线性方程组,且系统矩阵A必须是可逆的。

基于矩阵移位的方法:

因为我们有xA = b,所以(xA)^T = b^T <=> A*T^T= b^T,所以我们可以使用cv::解题(A.T(),b.t(),x),x.t()是这样的结果:

代码语言:javascript
复制
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()所提供的所有功能。

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23749932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档