Eigen的配置和使用(GAMES101-0作业)

VS STIDO配置Eigen库

配置教程

Eigen库的使用

Eigen库基础使用手册

GAMES101-0作业

 C++代码如下:

#include <iostream>
#include <Eigen/Dense>
#include <Eigen/Core>
#include <graphics.h>

using namespace std;

int main()
{
	// 向量的定义
	Eigen::Vector3f v(1, 0, 0);
	Eigen::Vector3f w(0, 1, 0);
	// 向量的加减运行
	cout << "v + w:" << endl << v + w << endl;
	cout << "v - w:" << endl << v - w << endl;
	cout << "v * 2:" << endl << v * 2 << endl;
	// 向量的点乘和叉乘
	cout << "v·w:" << endl << v.dot(w) << endl;
	cout << "v×w:" << endl << v.cross(w) << endl;
	// 向量的大小
	cout << "v.size:" << endl << v.size() << endl;
	// 向量元素的访问
	cout << "v(0):" << v(0) << " v[0]:" << v[0] << endl;
	cout << "v{0->1}:" << endl << v.head(2) << endl;
	cout << "v{end-3->end}:" << endl << v.tail(3) << endl;
	cout << "v{i->i+j-1}:" << endl << v.segment(0,2) << endl;

	// 矩阵的定义
	Eigen::Matrix3f A, B;
	// 矩阵数据的赋值(按行赋值)
	A << 1, 2, 3, 4, 5, 6, 7, 8, 9;
	B << 2, 3, 1, 4, 6, 5, 9, 7, 8;
	cout << "A:" << endl << A << endl;
	cout << "B:" << endl << B << endl;
	// 矩阵的转置和求和
	cout << "A(T)" << endl << A.transpose() << endl;
	cout << "A+B:" << endl << A + B << endl;
	
	// 矩阵求逆
	Eigen::Matrix2f C;
	C << 1, 1, -1, 1;
	cout << "C:" << endl << C << endl;
	cout << "C(-1)" << endl << C.inverse() << endl;
	cout << "CC(-1)" << endl << C * C.inverse() << endl;
	return 0;
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

仰望—星空

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值