Skip to content

Commit 17e7ace

Browse files
hshosesalkinium
authored andcommitted
[examples] Add Eigen matrix example
1 parent 29e6131 commit 17e7ace

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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/Dense>
13+
14+
using namespace Board;
15+
16+
int
17+
main()
18+
{
19+
Board::initialize();
20+
LedD13::setOutput();
21+
22+
while (1)
23+
{
24+
Eigen::Matrix2f mat{{1, 2}, {3, 4}};
25+
Eigen::Vector2f u{-1, 1}, v{2, 0};
26+
MODM_LOG_INFO << "Here is mat*mat:\n" << mat * mat << modm::endl;
27+
MODM_LOG_INFO << "Here is mat*u:\n" << mat * u << modm::endl;
28+
MODM_LOG_INFO << "Here is u^T*mat:\n" << u.transpose() * mat << modm::endl;
29+
MODM_LOG_INFO << "Here is u^T*v:\n" << u.transpose() * v << modm::endl;
30+
MODM_LOG_INFO << "Here is u*v^T:\n" << u * v.transpose() << modm::endl;
31+
MODM_LOG_INFO << "Let's multiply mat by itself" << modm::endl;
32+
mat = mat * mat;
33+
MODM_LOG_INFO << "Now mat is mat:\n" << mat << modm::endl;
34+
35+
modm::delay(1s);
36+
}
37+
38+
return 0;
39+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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:eigen</module>
9+
</modules>
10+
</library>

0 commit comments

Comments
 (0)