实验环境
eigen 3.40
下载链接 https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.zip
Visual Studio 2022配置
解压eigen后,在项目中配置包含目录
代码示例
加头文件
#include <Eigen/Dense>
using namespace Eigen;
矩阵运算
MatrixXd a(8, 6);
for (size_t i = 0; i < vecGSYConfigs.size(); ++ i)
{
std::shared_ptr<CGSYConfig> pGSYConfig = vecGSYConfigs[i];
if (!pGSYConfig)
{
continue;
}
a(i, 0) = pGSYConfig->m_dCol1;
a(i, 1) = pGSYConfig->m_dCol2;
a(i, 2) = pGSYConfig->m_dCol3;
a(i, 3) = pGSYConfig->m_dCol4;
a(i, 4) = pGSYConfig->m_dCol5;
a(i, 5) = pGSYConfig->m_dCol6;
}
VectorXd b(8);
b(0) = ui->doubleSpinBox_Z2->value();
b(1) = ui->doubleSpinBox_Z3->value();
b(2) = ui->doubleSpinBox_Z4->value();
b(3) = ui->doubleSpinBox_Z5->value();
b(4) = ui->doubleSpinBox_Z6->value();
b(5) = ui->doubleSpinBox_Z7->value();
b(6) = ui->doubleSpinBox_Z8->value();
b(7) = ui->doubleSpinBox_Z9->value();
VectorXd z = a.householderQr().solve(b);
z = z * 0.01;
std::cout << "z: " << z.transpose() << std::endl;
参数与结果示例
矩阵a
向量b
结果z