Arduino sketch that demonstrates some of the basic features.
- Boards:
- Nano 33 BLE, Teensy 4.x, ESP8266, ESP32
Aimed at Arduino boards with STL ostream support. Tested on ESP32 and Teensy 4.0 (beta). Also compiles for Arduino SAMD (Zero) and Arduino Nano 33 BLE, but untested.
Expected output
Solve system Ax = v
-------------------
A =
1 6 2
3 2 1
5 1 3
v =
9
6
9
QR factorization of A:
Q =
-0.169031 0.963676 -0.206779
-0.507093 0.0948696 0.856654
-0.845154 -0.249657 -0.472637
R =
-5.91608 -2.87352 -3.38062
0 5.72214 1.27325
0 0 -0.974814
solution x =
1
1
1
Basic matrix operations
-----------------------
C×B + D =
32 39
61 77
Basic vector operations
-----------------------
a = 1 2 3
b = 4 6 5
a×b = -8 7 -2
a·b = 31
Element access
--------------
A[2,0] = 5
A[2,0] ← 100
A =
1 6 2
3 2 1
100 1 3
using arduino::cout;
Serial.begin(115200);
while (!Serial)
;
cout.precision(6);
cout << "Solve system Ax = v \n"
"------------------- \n\n";
{1, 6, 2},
{3, 2, 1},
{5, 1, 3},
};
cout << "A = \n"
<< A << "\n"
<< "v = \n"
<< v << "\n"
<< "QR factorization of A: \n"
<< qr << "\n"
<< "solution x = \n"
<< x << std::endl;
cout << "Basic matrix operations \n"
"----------------------- \n\n";
{1, 2},
{3, 4},
{5, 6},
};
{1, 2, 3},
{4, 5, 6},
};
{10, 11},
{12, 13},
};
cout << " C×B + D = \n" << (C * B + D) << std::endl;
cout << "Basic vector operations \n"
"----------------------- \n\n";
cout << "a = " << a << "\n"
<< "b = " << b << "\n"
<<
"a×b = " << a.
cross(b) <<
"\n"
<<
"a·b = " << a.
dot(b) <<
"\n\n"
<< std::endl;
cout << "Element access \n"
"-------------- \n\n";
cout << "A[2,0] = " << A(2, 0) << std::endl;
cout << "A[2,0] ← 100" << std::endl;
A(2, 0) = 100;
cout << "A = \n" << A << std::endl;
}
Arduino std::ostream Serial wrapper.
QR factorization using Householder reflectors.
Matrix solve(const Matrix &B) const
Solve the system AX = B or QRX = B.
A row vector (1×n matrix).
static RowVector cross(const RowVector &a, const RowVector &b)
Compute the cross product of two 3-vectors.
static double dot(const RowVector &a, const RowVector &b)
Compute the dot product of two vectors.
A column vector (n×1 matrix).
static Vector ones(size_t size)
Create a vector filled with ones.