Согласно документации для Eigen::MatrixBase::selfadjointview
, функция уже создает симметричный c вид из верхней или нижней части tri angular.
Matrix3i m = Matrix3i::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the symmetric matrix extracted from the upper part of m:" << endl
<< Matrix3i(m.selfadjointView<Upper>()) << endl;
cout << "Here is the symmetric matrix extracted from the lower part of m:" << endl
<< Matrix3i(m.selfadjointView<Lower>()) << endl;
Вывод:
Here is the matrix m:
7 6 -3
-2 9 6
6 -6 -5
Here is the symmetric matrix extracted from the upper part of m:
7 6 -3
6 9 6
-3 6 -5
Here is the symmetric matrix extracted from the lower part of m:
7 -2 6
-2 9 -6
6 -6 -5
Если ваша матрица имеет верхний три angular, следующий ответ должен ответить на ваш вопрос.
Matrix3i m = [] {
Matrix3i tmp;
tmp << 1, 2, 3, 0, 4, 5, 0, 0, 6;
return tmp;
}();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the symmetric matrix extracted from the upper part of m:" << endl
<< Matrix3i(m.selfadjointView<Upper>()) << endl;
Вывод:
Here is the matrix m:
1 2 3
0 4 5
0 0 6
Here is the symmetric matrix extracted from the upper part of m:
1 2 3
2 4 5
3 5 6