我是靠谱客的博主 成就黄蜂,这篇文章主要介绍[Eigen]Eigen的单位矩阵C++Eigen 单位矩阵,现在分享给大家,希望可以做个参考。

Eigen 单位矩阵

单位矩阵可以用来求解矩阵的逆矩阵,matlab,numpy或者eigen这些库都已经内置了很简单的实现方法
Eigen中有自带的单位矩阵实现方法,在matlab中,单位矩阵的函数为eye(row,col)。
在visual studio中新建空项目,命名为Identity,新建main.cpp,然后键入如下代码,验证输出

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "../Common/common.h" using namespace Eigen; using namespace std; int main() { /*单位矩阵**/ Matrix<double, Dynamic, Dynamic> m_matrix; MatrixXd m_matrix2(3,3); m_matrix2 << 1,2,3, 4,5,6, 7,8,8; cout << "MatrixXd::Identity(5, 4):n"<<MatrixXd::Identity(5, 4) << endl;; m_matrix.setIdentity(5, 4); cout << "m_matrix.setIdentity(5, 4):n" << m_matrix << endl; /*求逆矩阵需要先判断是否可逆**/ cout << "m_matrix2.inverse():n" << m_matrix2.inverse() << endl; /*逐元素取倒数**/ cout << "m_matrix.array().inverse():n" << m_matrix.array().inverse() << endl; cout << "m_matrix.cwiseInverse():n" << m_matrix.cwiseInverse() << endl; return 0; }

#运行结果
在这里插入图片描述

矩阵 A A A,逆矩阵为 A − 1 A^{-1} A1,逆矩阵和矩阵乘积为单位矩阵。

最后

以上就是成就黄蜂最近收集整理的关于[Eigen]Eigen的单位矩阵C++Eigen 单位矩阵的全部内容,更多相关[Eigen]Eigen的单位矩阵C++Eigen内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部