openGPMP
Open Source Mathematics Package
linsys.hpp
Go to the documentation of this file.
1 /*************************************************************************
2  *
3  * Project
4  * _____ _____ __ __ _____
5  * / ____| __ \| \/ | __ \
6  * ___ _ __ ___ _ __ | | __| |__) | \ / | |__) |
7  * / _ \| '_ \ / _ \ '_ \| | |_ | ___/| |\/| | ___/
8  *| (_) | |_) | __/ | | | |__| | | | | | | |
9  * \___/| .__/ \___|_| |_|\_____|_| |_| |_|_|
10  * | |
11  * |_|
12  *
13  * Copyright (C) Akiel Aries, <akiel@akiel.org>, et al.
14  *
15  * This software is licensed as described in the file LICENSE, which
16  * you should have received as part of this distribution. The terms
17  * among other details are referenced in the official documentation
18  * seen here : https://akielaries.github.io/openGPMP/ along with
19  * important files seen in this project.
20  *
21  * You may opt to use, copy, modify, merge, publish, distribute
22  * and/or sell copies of the Software, and permit persons to whom
23  * the Software is furnished to do so, under the terms of the
24  * LICENSE file. As this is an Open Source effort, all implementations
25  * must be of the same methodology.
26  *
27  *
28  *
29  * This software is distributed on an AS IS basis, WITHOUT
30  * WARRANTY OF ANY KIND, either express or implied.
31  *
32  ************************************************************************/
33 
34 #ifndef LINSYS_HPP
35 #define LINSYS_HPP
36 
37 #include <utility>
38 #include <vector>
39 
40 namespace gpmp {
41 
42 namespace linalg {
43 
48 class LinSys {
49  public:
50  std::vector<std::vector<double>> matrix;
51  int num_rows;
52  int num_cols;
53 
58  LinSys(const std::vector<std::vector<double>> &mat);
59 
63  void display_mtx() const;
64 
65  void display(const std::vector<std::vector<double>> &mat) const;
66 
71  std::vector<double> solve_gauss();
72 
77  double determinant() const;
78 
82  void invert_mtx();
83 
88  std::pair<std::vector<std::vector<double>>,
89  std::vector<std::vector<double>>>
90  lu_decomp();
91 
95  void solve_lu();
96 
100  void solve_cholesky();
101 
107  void solve_jacobi(int maxIterations = 100, double tolerance = 1e-10);
108 
113  bool is_symmetric() const;
114 
119  double frobenius_norm() const;
120 
125  double one_norm() const;
126 
131  double inf_norm() const;
132 
136  void gram_schmidt();
137 
142  bool diagonally_dominant() const;
143 
148  bool is_consistent() const;
149 
154  bool is_homogeneous() const;
155 };
156 } // namespace linalg
157 } // namespace gpmp
158 
159 #endif
Class for solving linear systems and performing matrix operations.
Definition: linsys.hpp:48
std::vector< std::vector< double > > matrix
Definition: linsys.hpp:50
void display_mtx() const
Display the augmented matrix.
Definition: linsys.cpp:47
bool is_consistent() const
Check if the linear system is consistent.
Definition: linsys.cpp:413
double inf_norm() const
Calculate the infinity norm of the matrix.
Definition: linsys.cpp:362
double frobenius_norm() const
Calculate the Frobenius norm of the matrix.
Definition: linsys.cpp:338
bool diagonally_dominant() const
Check if the matrix is diagonally dominant.
Definition: linsys.cpp:396
void invert_mtx()
Invert the matrix.
Definition: linsys.cpp:135
void gram_schmidt()
Perform Gram-Schmidt orthogonalization on the matrix.
Definition: linsys.cpp:375
void solve_cholesky()
Solve the linear system using Cholesky decomposition.
Definition: linsys.cpp:214
void solve_jacobi(int maxIterations=100, double tolerance=1e-10)
Solve the linear system using Jacobi iteration.
Definition: linsys.cpp:263
double determinant() const
Calculate the determinant of the matrix.
Definition: linsys.cpp:107
void solve_lu()
Solve the linear system using LU decomposition.
Definition: linsys.cpp:195
LinSys(const std::vector< std::vector< double >> &mat)
Constructor for LinSys class.
Definition: linsys.cpp:40
std::pair< std::vector< std::vector< double > >, std::vector< std::vector< double > > > lu_decomp()
Perform LU decomposition of the matrix.
Definition: linsys.cpp:165
std::vector< double > solve_gauss()
Solve the linear system using Gaussian Elimination.
Definition: linsys.cpp:70
bool is_homogeneous() const
Check if the linear system is homogeneous.
Definition: linsys.cpp:432
bool is_symmetric() const
Check if the matrix is symmetric.
Definition: linsys.cpp:302
void display(const std::vector< std::vector< double >> &mat) const
Definition: linsys.cpp:56
double one_norm() const
Calculate the 1-norm of the matrix.
Definition: linsys.cpp:349
The source C++ openGPMP namespace.