Skip to content

Commit e10ac7d

Browse files
committed
[examples] Add Eigen matrix example
1 parent 7544073 commit e10ac7d

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2025, Henrik Hose
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#include <modm/board.hpp>
12+
#include <Eigen/Eigen>
13+
14+
using namespace Board;
15+
16+
Eigen::IOFormat squarebrackets(5, 0, ", ", "\n", "[", "]");
17+
18+
int
19+
main()
20+
{
21+
Board::initialize();
22+
LedD13::setOutput();
23+
24+
while (1)
25+
{
26+
Eigen::Matrix2f mat{{1.111f, 2.2222f}, {3.333f, 4.4f}};
27+
Eigen::Vector2f u{-1.1f, 1.5f}, v{2.2f, 0.5f};
28+
MODM_LOG_INFO.width(2);
29+
MODM_LOG_INFO.precision(0);
30+
MODM_LOG_INFO << "Here is mat*mat:\n" << mat * mat << modm::endl;
31+
MODM_LOG_INFO.width(5);
32+
MODM_LOG_INFO.precision(1);
33+
MODM_LOG_INFO << "Here is mat*u:\n" << mat * u << modm::endl;
34+
MODM_LOG_INFO.width(8);
35+
MODM_LOG_INFO.precision(3);
36+
MODM_LOG_INFO << "Here is u^T*mat:\n" << u.transpose() * mat << modm::endl;
37+
MODM_LOG_INFO.width(10);
38+
MODM_LOG_INFO.precision(5);
39+
MODM_LOG_INFO << "Here is u^T*v:\n" << u.transpose() * v << modm::endl;
40+
MODM_LOG_INFO.width(15);
41+
MODM_LOG_INFO.precision(7);
42+
MODM_LOG_INFO << "Here is u*v^T:\n" << u * v.transpose() << modm::endl;
43+
MODM_LOG_INFO << "Let's multiply mat by itself" << modm::endl;
44+
mat = mat * mat;
45+
MODM_LOG_INFO << "Now mat is mat:\n" << mat.format(squarebrackets) << modm::endl;
46+
47+
modm::delay(1s);
48+
}
49+
50+
return 0;
51+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<library>
2+
<extends>modm:nucleo-g474re</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/nucleo_g474re/eigen</option>
5+
</options>
6+
<modules>
7+
<module>modm:build:scons</module>
8+
<module>modm:platform:heap</module>
9+
<module>modm:eigen</module>
10+
</modules>
11+
</library>

0 commit comments

Comments
 (0)