1template <
int Rows,
typename Scalar>
3 const Matrix<Rows, Rows, Scalar>& R,
8 for (
int k = Rows - 1;
k >= 0;
k--) {
10 for (
int i = k + 1;
i < Rows;
i++) {
11 x(k) -=
R(k, i) *
x(i);
13 x(k) =
x(k) /
R(k, k);
20template <
int Rows,
typename Scalar>
22 for (
int k = 0; k < Rows; k++) {
25 for (
int i = k + 1; i < Rows; i++) {
35 for (
int j = 0; j < Rows; j++) {
36 Scalar
temp = A(k, j);
37 A(k, j) = A(maxIndex, j);
38 A(maxIndex, j) =
temp;
42 for (
int i = k + 1; i < Rows; i++) {
47 for (
int i = k + 1; i < Rows; i++) {
48 for (
int j = k + 1; j < Rows; j++) {
49 A(i, j) -= A(i, k) * A(k, j);
56template <
int Rows,
typename Scalar>
58 for (
int k = 0; k < Rows; k++) {
60 for (
int i = k + 1; i < Rows; i++) {
65 for (
int i = k + 1; i < Rows; i++) {
66 for (
int j = k + 1; j < Rows; j++) {
67 A(i, j) -= A(i, k) * A(k, j);
74template <
typename Scalar>
76 return R(0, 0) * R(1, 1) - R(0, 1) * R(1, 0);
80template <
int Rows,
typename Scalar>
89 for (
int j = 0; j < Rows; j++) {
90 for (
int i = 0; i < Rows; i++) {
91 result(i, j) = ((i == j) ?
static_cast<Scalar
>(1) :
static_cast<Scalar
>(0));
92 for (
int k = 0; k < i; k++) {
93 result(i, j) -= LU(i, k) * result(k, j);
97 for (
int i = Rows - 1;
i >= 0;
i--) {
98 for (
int k = i + 1;
k < Rows;
k++) {
99 result(i, j) -= LU(i, k) * result(k, j);
101 result(i, j) /= LU(i, i);
120 returnCode = LAPACKE_dgetrf(
133 returnCode = LAPACKE_dgetri(LAPACK_ROW_MAJOR, Rows,
M.data(), Rows, ipiv);
141template <
typename Scalar>
144 Matrix<2, 2, Scalar> result;
147 const double scaling = 1.0 /
det(R);
149 result(0, 0) =
R(1, 1) * scaling;
150 result(0, 1) = -
R(0, 1) * scaling;
151 result(1, 0) = -
R(1, 0) * scaling;
152 result(1, 1) =
R(0, 0) * scaling;
158template <
typename Scalar>
160 return R(0, 0) * (R(1, 1) * R(2, 2) - R(2, 1) * R(1, 2))
161 - R(0, 1) * (R(1, 0) * R(2, 2) - R(1, 2) * R(2, 0))
162 + R(0, 2) * (R(1, 0) * R(2, 1) - R(1, 1) * R(2, 0));
166template <
typename Scalar>
169 Matrix<3, 3, Scalar> result;
172 double invdet = 1 / det(R);
174 result(0, 0) = (R(1, 1) * R(2, 2) - R(2, 1) * R(1, 2)) * invdet;
175 result(0, 1) = (R(0, 2) * R(2, 1) - R(0, 1) * R(2, 2)) * invdet;
176 result(0, 2) = (R(0, 1) * R(1, 2) - R(0, 2) * R(1, 1)) * invdet;
177 result(1, 0) = (R(1, 2) * R(2, 0) - R(1, 0) * R(2, 2)) * invdet;
178 result(1, 1) = (R(0, 0) * R(2, 2) - R(0, 2) * R(2, 0)) * invdet;
179 result(1, 2) = (R(1, 0) * R(0, 2) - R(0, 0) * R(1, 2)) * invdet;
180 result(2, 0) = (R(1, 0) * R(2, 1) - R(2, 0) * R(1, 1)) * invdet;
181 result(2, 1) = (R(2, 0) * R(0, 1) - R(0, 0) * R(2, 1)) * invdet;
182 result(2, 2) = (R(0, 0) * R(1, 1) - R(1, 0) * R(0, 1)) * invdet;
double f(double p4, double p1, double p5, double rho1, double rho5, double gamma)
Matrix< Rows, Rows, Scalar > invert(const Matrix< Rows, Rows, Scalar > &M)
Invert matrix with LU decomposition.
Vector< Rows, Scalar > backSubstitution(const Matrix< Rows, Rows, Scalar > &R, const Vector< Rows, Scalar > &f)
Back substitution following LU decomposition.
double det(const Matrix< 2, 2, Scalar > &R)
double max(double a, double b, double c)
I need the maximum of three values all the time, to I decided to write a function for this.
void lu(Matrix< Rows, Rows, Scalar > &A, Vector< Rows, int > &pivots)
Performs an in-situ LU-decomposition of the square matrix A.