Eigen(8)实例最小二乘法
生活随笔
收集整理的這篇文章主要介紹了
Eigen(8)实例最小二乘法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
用Eigen庫解Ax=b線性方程,使用最小二乘法
#include <iostream>#include <Eigen/Dense>using namespace std;using namespace Eigen;int main(){//對方程Ax=bMatrixXf A = MatrixXf::Random(3, 2);std::cout << "Here is the matrix A:\n" << A << std::endl;VectorXf b = VectorXf::Random(3);std::cout << "Here is the right hand side b:\n" << b << std::endl;cout << endl;cout << endl;cout << "**********jacobiSvd方法********************" << endl;MatrixXf x_jacobiSvd, x_colPivHouseholderQr;//jacobiSvd 方式:Slow (but fast for small matrices)x_jacobiSvd = A.jacobiSvd(ComputeThinU | ComputeThinV).solve(b);std::cout << "The least-squares solution is:\n"<< A.jacobiSvd(ComputeThinU | ComputeThinV).solve(b) << std::endl;cout << endl;cout << endl;cout << "**********colPivHouseholderQr方法********************" << endl;x_colPivHouseholderQr = A.colPivHouseholderQr().solve(b);//colPivHouseholderQr方法:faststd::cout << "The least-squares solution is:\n"<< x_colPivHouseholderQr << std::endl;system("pause");return 0;}?
總結
以上是生活随笔為你收集整理的Eigen(8)实例最小二乘法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vector 中的元素去重
- 下一篇: Eigen(7)Map类