我的代码中提到的部分的目的是求解线性方程Ax = b“A”作为方形矩阵,“b”作为具有相同大小的矢量:
问题是,当我尝试在我的函数中使用Eigen函数时,编译失败:
#include "Eigen/Dense"
using namespace Eigen;
void StreamTemperature::avgTemperature() {
TotalDist = pm->get_total_dist();
vector<vector<double>> A(TotalDist, std::vector<double>(TotalDist));
vector<double> b_copy;
VectorXd x_eigen; //Eigen format!
MatrixXd A_eigen(TotalDist, TotalDist);
VectorXd b_eigen(TotalDist);
for (int i = 0; i < (TotalDist - 1); i++) {
A[i + 1][i] = 1.0;
A[i][i] = 5.0;
A[i][i + 1] = -1.0;
}
A[TotalDist - 1][TotalDist - 1] = b[TotalDist - 1][j] + c[TotalDist - 1][j];
b_copy.resize(TotalDist);
for (int i = 0; i < TotalDist; i++) { b_copy[i] = 10.0; }
for (int i = 0; i < TotalDist; i++)
A_eigen.row(i) = Map<VectorXd>(A[i].data(), TotalTime);
for (int i = 0; i < TotalDist; i++)
b_eigen(i) = b_copy[i];
x_eigen = A_eigen.colPivHouseholderQr().solve(b_eigen);
for (int i = 0; i < TotalDist; i++) {
x[i] = x_eigen(i);
}
}
Eigen相关部分在anohter项目中运作良好但我在这里遇到问题! 这是编译错误:
1>e:\suny-files\spring2017\summer2017\runforsyracusemin\itreecoolnewsw\eigen\src/Core/PlainObjectBase.h(659): error C2338: FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED
1>e:\suny-files\spring2017\summer2017\runforsyracusemin\itreecoolnewsw\eigen\src/Core/Matrix.h(250): note: see reference to function template instantiation 'void Eigen::PlainObjectBase<Eigen::Matrix<double,-1,-1,0,-1,-1>>::_init2<T0,T1>(int,int,double *)' being compiled
1> with
1> [
1> T0=double,
1> T1=double
1> ]
有什么想法吗?! :|
答案 0 :(得分:1)
在声明A_eigen时,尝试将TotalDist显式地转换为int。编译错误显示您正在传递浮点数,其中包含一个into。
同时检查TotalDist的值和A_eigen的尺寸。