nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
numerics.hpp
Go to the documentation of this file.
1
3// toolboxes/control/include/nk/control/internal/numerics.hpp
4//
5// Shared numerical kernels for toolboxes/control. All matrices are stored
6// column-major in flat std::vector<double>.
7//
8// This header is INTERNAL — only toolboxes/control TUs include it. The
9// kernels were originally inline-duplicated in response/discretize/
10// freq/lyapunov/state, leading to ~4× the LU code, 2× the expm code
11// and 2× the Faddeev char-poly code. Cycle 44 of the autonomous
12// /loop consolidates them here. No behavioural change.
13
14#pragma once
15
16#include <cstddef>
17#include <vector>
18
19namespace nk::control::internal {
20
23
24
25using Mat = std::vector<double>;
26using Vec = std::vector<double>;
27
41bool solveInPlace(Mat &A, Mat &B, std::size_t n, std::size_t nrhs);
42
54Mat expm(const Mat &A, std::size_t n);
55
68Vec charPoly(const Mat &A, std::size_t n);
69
76Mat matmulSq(const Mat &A, const Mat &B, std::size_t n);
77
78
80} // namespace nk::control::internal
bool solveInPlace(Mat &A, Mat &B, std::size_t n, std::size_t nrhs)
In-place partial-pivot LU decomposition + back-substitution.
Mat expm(const Mat &A, std::size_t n)
Matrix exponential via the canonical [6/6] Padé approximant with scaling and squaring.
Mat matmulSq(const Mat &A, const Mat &B, std::size_t n)
Square matrix multiply C = A·B (all n×n column-major).
Vec charPoly(const Mat &A, std::size_t n)
Faddeev–LeVerrier characteristic polynomial of an n×n column-major matrix.