MCPcopy Create free account
hub / github.com/BIMCoderLiang/LNLib / SolveLinearSystem

Method SolveLinearSystem

src/LNLib/Mathematics/Utils/MathUtils.cpp:258–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256}
257
258std::vector<std::vector<double>> LNLib::MathUtils::SolveLinearSystem(
259 const std::vector<std::vector<double>>& matrix,
260 const std::vector<std::vector<double>>& right)
261{
262 if (matrix.empty() || right.empty() || matrix[0].empty() || right[0].empty()) {
263 return {};
264 }
265
266 int rows = static_cast<int>(matrix.size());
267 int cols = static_cast<int>(matrix[0].size());
268 int rhsCols = static_cast<int>(right[0].size());
269
270 Eigen::MatrixXd A(rows, cols);
271 for (int i = 0; i < rows; ++i) {
272 A.row(i) = Eigen::VectorXd::Map(&matrix[i][0], matrix[i].size());
273 }
274
275 Eigen::MatrixXd B(right.size(), rhsCols);
276 for (int i = 0; i < right.size(); ++i) {
277 B.row(i) = Eigen::VectorXd::Map(&right[i][0], right[i].size());
278 }
279
280 Eigen::MatrixXd X = A.colPivHouseholderQr().solve(B);
281
282 std::vector<std::vector<double>> result(cols, std::vector<double>(rhsCols));
283 for (int j = 0; j < rhsCols; ++j) {
284 for (int i = 0; i < cols; ++i) {
285 result[i][j] = X(i, j);
286 }
287 }
288 return result;
289}
290bool LNLib::MathUtils::SolveLinearSystemBanded(int matrixDimension, const std::vector<std::vector<double>>& matrix, int bandwidth, const std::vector<std::vector<double>>& right, std::vector<std::vector<double>>& result)
291{
292 int sbw = bandwidth / 2;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected