线性阿尔法方程Ax = By的最小二乘解 [英] Least Squares Solution of Linear Algerbraic Equation Ax = By in Eigen C++

查看:1004
本文介绍了线性阿尔法方程Ax = By的最小二乘解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组矩阵形式的线性代数方程, Ax = By A 36x20 x 的矩阵是大小 20 B 36x13 y 13x1 Rank(A)= 20 。因为系统是超定的(有比变量更多的方程),所以最小二乘解是可能的,i,e; x =(A ^ TA)^ - 1A ^ TBy 。我想要解决方案,以便剩余误差e = Ax-By应该最小化。



使用 Eigen / Dense C ++的库已经制定了所有的矩阵等。我尝试本页上描述的方法
Eigen Tutorial



我猜这个页面描述的方法只适用于方阵。因为当它试图运行这个错误。

  x = A.jacobiSvd(ComputeThinU | ComputeThinV).solve(B * y); 

错误

  /usr/include/eigen3/Eigen/src/SVD/JacobiSVD.h:在成员函数'const 
中Eigen :: internal :: solve_retval< Eigen :: JacobiSVD< MatrixType,QRPreconditioner>,Rhs&
Eigen :: JacobiSVD< MatrixType,QRPreconditioner> :: solve(const
Eigen :: MatrixBase< OtherDerived>&)const [with Rhs =
Eigen :: GeneralProduct& ; float,36,13>,Eigen :: Matrix< double,-1,1>,4>
_MatrixType = Eigen :: Matrix< float,36,20> ;; int QRPreconditioner = 2]':
/usr/include/eigen3/Eigen/src/SVD/JacobiSVD.h:658:5:warning:控制到达
结束非空函数[-Wreturn-类型]
make [2]:*** [src / CMakeFiles / spacebot_actuationKinematics.dir
/ActuationKinematics.cpp.o]错误1
make [1]:*** [src / CMakeFiles / spacebot_actuationKinematics.dir / all]错误2
make:*** [all]错误2


ComputeThin * 选项只适用于动态大小的矩阵。对于固定大小,您必须使用 ComputeFull * 。不过,在你的情况下,最好使用动态大小矩阵,即 MatrixXf 。固定大小矩阵只对非常小的矩阵有意义。



最后,ColPivHouseholderQR可能是最小二乘解的更好的选择。 SVD有点过分。


I have a set of linear algebraic equations in matrices form, Ax=By. Where A is matrix of 36x20 and x is a vector of size 20, B is 36x13 and y is 13x1. Rank(A)=20. Because system is overdetermined (there are more number of equations than the variables), so least squares solution is possible, i,e; x = (A^TA)^-1A^TBy. I want the solution so that the residual error e = Ax-By should be minimized.

Using Eigen/Dense library of C++ i have formulated all the matrices etc. I tried the method described on this page Eigen Tutorial!

I guess the method described in this page is only for square matrices. Because when it try to run this it gives error.

 x = A.jacobiSvd( ComputeThinU | ComputeThinV ).solve(B*y);

Error

 /usr/include/eigen3/Eigen/src/SVD/JacobiSVD.h: In member function 'const    
 Eigen::internal::solve_retval<Eigen::JacobiSVD<MatrixType, QRPreconditioner>, Rhs> 
 Eigen::JacobiSVD<MatrixType, QRPreconditioner>::solve(const 
 Eigen::MatrixBase<OtherDerived>&) const [with Rhs = 
 Eigen::GeneralProduct<Eigen::Matrix<float, 36, 13>, Eigen::Matrix<double, -1, 1>, 4>; 
 _MatrixType = Eigen::Matrix<float, 36, 20>; int QRPreconditioner = 2]':
 /usr/include/eigen3/Eigen/src/SVD/JacobiSVD.h:658:5: warning: control reaches end of  
 non-void function [-Wreturn-type]
 make[2]: *** [src/CMakeFiles/spacebot_actuationKinematics.dir 
 /ActuationKinematics.cpp.o] Error 1
 make[1]: *** [src/CMakeFiles/spacebot_actuationKinematics.dir/all] Error 2
 make: *** [all] Error 2

解决方案

As explained in the documentation, the ComputeThin* options are only for Dynamic sized matrices. For fixed sizes, you must use ComputeFull*. Nevertheless, in your case it is better to use Dynamic size matrices, i.e., MatrixXf. Fixed size matrices only makes sense for very small ones.

Finally, ColPivHouseholderQR is probably a better choice for least-square solving. SVD is a bit overkill.

这篇关于线性阿尔法方程Ax = By的最小二乘解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆