0
我想用特征库添加一个矩阵,我的结果在数值上确定,但它缺少负号。正确添加之后的结果是最终添加失去负号。所有矩阵都声明为double。本征矩阵加上负号丢失
我有这样的代码在两种情况下:
for(int i=0;i<9;i++){
mata<<MatrixXd::Zero(4,4);
for(int j=0;i<4;j++){
mata += matb.transpose()*(matc*matb)*scalar;
}
cout<<mata<<endl;
}
我也尝试:
for(int i=0;i<9;i++){
mata<<MatrixXd::Zero(4,4);
for(int j=0;i<4;j++){
MatrixXd aux=matb.transpose();
MatrixXd aux2=(matc*matb)*scalar
mata += aux*aux2;
}
cout<<mata<<endl;
}
Matlab的结果:
1.92186 -0.960928 -0.960928 -5.55112e-17
-0.960928 1.92186 -5.55112e-17 -0.960928
-0.960928 -5.55112e-17 1.92186 -0.960928
-5.55112e-17 -0.960928 -0.960928 1.92186
征结果:
1.92186 -0.960928 -0.960928 5.55112e-17
-0.960928 1.92186 5.55112e-17 -0.960928
-0.960928 5.55112e-17 1.92186 -0.960928
5.55112e-17 -0.960928 -0.960928 1.92186