Arduino sketch that demonstrates some of the basic features.
- Boards:
- Nano 33 IoT, Teensy 3.x
Aimed at Arduino boards without STL ostream support. Tested on Teensy 3.2, compiles for Teensy 3.0, 3.5, 3.6 as well.
Expected output
Solve system Ax = v
-------------------
A =
1.000000e+00 6.000000e+00 2.000000e+00
3.000000e+00 2.000000e+00 1.000000e+00
5.000000e+00 1.000000e+00 3.000000e+00
v =
9.000000e+00
6.000000e+00
9.000000e+00
QR factorization of A:
Q =
-1.690309e-01 9.636759e-01 -2.067787e-01
-5.070926e-01 9.486964e-02 8.566545e-01
-8.451543e-01 -2.496570e-01 -4.726370e-01
R =
-5.916080e+00 -2.873524e+00 -3.380617e+00
0.000000e+00 5.722137e+00 1.273250e+00
0.000000e+00 0.000000e+00 -9.748137e-01
solution x =
1.000000e+00
1.000000e+00
1.000000e+00
Basic matrix operations
-----------------------
C×B + D =
3.200000e+01 3.900000e+01
6.100000e+01 7.700000e+01
Basic vector operations
-----------------------
a = 1.000000e+00 2.000000e+00 3.000000e+00
b = 4.000000e+00 6.000000e+00 5.000000e+00
a×b = -8.000000e+00 7.000000e+00 -2.000000e+00
a·b = 31.00
Element access
--------------
A[2,0] = 5.00
A[2,0] ← 100
1.000000e+00 6.000000e+00 2.000000e+00
3.000000e+00 2.000000e+00 1.000000e+00
1.000000e+02 1.000000e+00 3.000000e+00
Serial.begin(115200);
while (!Serial)
;
Serial.println("Solve system Ax = v");
Serial.println("-------------------\n");
{1, 6, 2},
{3, 2, 1},
{5, 1, 3},
};
Serial.println("A = ");
Serial.println(A);
Serial.println("v =");
Serial.println(v);
Serial.println("QR factorization of A:");
Serial.println("Q =");
Serial.println(qr.
get_Q());
Serial.println("R =");
Serial.println(qr.
get_R());
Serial.println("solution x =");
Serial.println(x_solution);
Serial.println("Basic matrix operations");
Serial.println("-----------------------\n");
{1, 2},
{3, 4},
{5, 6},
};
{1, 2, 3},
{4, 5, 6},
};
{10, 11},
{12, 13},
};
Serial.println("C×B + D =");
Serial.println(E);
Serial.println("Basic vector operations");
Serial.println("-----------------------\n");
Serial.print("a = ");
Serial.print(a);
Serial.print("b = ");
Serial.print(b);
Serial.print("a×b = ");
Serial.print(c);
Serial.print("a·b = ");
Serial.println(d);
Serial.println();
Serial.println("Element access");
Serial.println("--------------\n");
Serial.print("A[2,0] = ");
Serial.println(A(2, 0));
Serial.println("A[2,0] ← 100");
A(2, 0) = 100;
Serial.println("A =");
Serial.println(A);
}
QR factorization using Householder reflectors.
Matrix solve(const Matrix &B) const
Solve the system AX = B or QRX = B.
Matrix get_R() const &
Get a copy of the upper-triangular matrix R.
SquareMatrix get_Q() const
Compute the unitary matrix Q.
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.