Reaktoro  A unified framework for modeling chemically reactive systems
MathUtils.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright (C) 2014-2015 Allan Leal
4 //
5 // This program is free software: you can redistribute it and/or modify
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 #pragma once
19
20 // Reaktoro includes
21 #include <Reaktoro/Common/Index.hpp>
22 #include <Reaktoro/Math/Matrix.hpp>
23
24 namespace Reaktoro {
25
29 auto linearlyIndependentCols(const Matrix& A) -> Indices;
30
34 auto linearlyIndependentRows(const Matrix& A) -> Indices;
35
40 auto linearlyIndependentCols(const Matrix& A, Matrix& B) -> Indices;
41
46 auto linearlyIndependentRows(const Matrix& A, Matrix& B) -> Indices;
47
51 auto inverseShermanMorrison(const Matrix& invA, const Vector& D) -> Matrix;
52
59 auto rationalize(double x, unsigned maxden) -> std::tuple<long, long>;
60
64 auto cleanRationalNumbers(double* vals, long size, long maxden = 6) -> void;
65
69 auto cleanRationalNumbers(Matrix& A, long maxden = 6) -> void;
70
74 auto cleanRationalNumbers(Vector& x, long maxden = 6) -> void;
75
77 auto dot3p(const Vector& x, const Vector& y, double s) -> double;
78
80 auto residual3p(const Matrix& A, const Vector& x, const Vector& b) -> Vector;
81
82 } // namespace Reaktoro
Eigen::MatrixXd Matrix
Define an alias to the matrix type of the Eigen library.
Definition: Matrix.hpp:387
auto cleanRationalNumbers(double *vals, long size, long maxden) -> void
Clean an array that is known to have rational numbers from round-off errors.
Definition: MathUtils.cpp:114
std::vector< Index > Indices
Define a type that represents a collection of indices.
Definition: Index.hpp:29
auto dot3p(const Vector &x, const Vector &y, double s) -> double
Return the dot product s + dot(x, y) of two vectors with triple-precision.
Definition: MathUtils.cpp:159
auto residual3p(const Matrix &A, const Vector &x, const Vector &b) -> Vector
Return the residual of the equation A*x - b with triple-precision.
Definition: MathUtils.cpp:164
Eigen::VectorXd Vector
Define an alias to the vector type of the Eigen library.
Definition: Matrix.hpp:384
auto linearlyIndependentRows(const Matrix &A) -> Indices
Determine the set of linearly independent rows in a matrix.
Definition: MathUtils.cpp:38
auto inverseShermanMorrison(const Matrix &invA, const Vector &D) -> Matrix
Calculate the inverse of A + D where inv(A) is already known and D is a diagonal matrix.
Definition: MathUtils.cpp:64
auto rationalize(double x, unsigned maxden) -> std::tuple< long, long >
Calculates the rational number that approximates a given real number.
Definition: MathUtils.cpp:101
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
auto linearlyIndependentCols(const Matrix &A) -> Indices
Determine the set of linearly independent columns in a matrix using a column pivoting QR algorithm...
Definition: MathUtils.cpp:28