codac 2.0.0
Loading...
Searching...
No Matches
codac2_inversion.h File Reference
#include <ostream>
#include "codac2_Matrix.h"
#include "codac2_IntervalMatrix.h"
Include dependency graph for codac2_inversion.h:

Go to the source code of this file.

Functions

template<LeftOrRightInv O = LEFT_INV, typename OtherDerived, typename OtherDerived_>
IntervalMatrix codac2::inverse_correction (const Eigen::MatrixBase< OtherDerived > &A, const Eigen::MatrixBase< OtherDerived_ > &B)
 Correct the approximation of the inverse \(\mathbf{B}\approx\mathbf{A}^{-1}\) of a square matrix \(\mathbf{A}\) by providing a reliable enclosure \([\mathbf{A}^{-1}]\).
 
template<typename OtherDerived>
IntervalMatrix codac2::inverse_enclosure (const Eigen::MatrixBase< OtherDerived > &A)
 Enclosure of the inverse of a (non-singular) matrix expression, possibly an interval matrix.
 
IntervalMatrix codac2::infinite_sum_enclosure (const IntervalMatrix &A, double &mrad)
 Compute an upper bound of \(\left([\mathbf{A}]+[\mathbf{A}]^2+[\mathbf{A}]^3+\dots\right)\), with \([\mathbf{A}]\) a matrix of intervals as an "error term" (uses only bounds on coefficients).
 

Detailed Description

Date
2024
Author
Damien Massé
License: GNU Lesser General Public License (LGPL)

Function Documentation

◆ inverse_correction()

template<LeftOrRightInv O = LEFT_INV, typename OtherDerived, typename OtherDerived_>
IntervalMatrix codac2::inverse_correction ( const Eigen::MatrixBase< OtherDerived > & A,
const Eigen::MatrixBase< OtherDerived_ > & B )
inline

Correct the approximation of the inverse \(\mathbf{B}\approx\mathbf{A}^{-1}\) of a square matrix \(\mathbf{A}\) by providing a reliable enclosure \([\mathbf{A}^{-1}]\).

Precondition
\(\mathbf{A}\) and \(\mathbf{B}\) are square matrices, possibly interval matrices.
Template Parameters
OIf LEFT_INV, use the inverse of \(\mathbf{BA}\) (otherwise use the inverse of \(\mathbf{AB}\), left inverse is normally better). In Python/Matlab, this template parameter is provided as a last boolean argument, and is left_inv = True by default.
Parameters
AA matrix expression, possibly interval.
BAn (almost punctual) approximation of its inverse.
Returns
The enclosure of the inverse.
36 {
37 assert_release(A.is_squared());
38 assert_release(B.is_squared());
39
40 auto A_ = A.template cast<Interval>();
41 auto B_ = B.template cast<Interval>();
42
43 Index N = A_.rows();
44 assert_release(N==B_.rows());
45
46 auto Id = IntervalMatrix::Identity(N,N);
47 auto erMat = [&]() { if constexpr(O == LEFT_INV) return -B_*A_+Id; else return -A_*B_+Id; }();
48
49 double mrad=0.0;
50 IntervalMatrix E = infinite_sum_enclosure(erMat,mrad);
51 IntervalMatrix Ep = Id+erMat*(Id+E);
52 /* one could use several iterations here, either
53 using mrad, or directly */
54
55 auto res = (O == LEFT_INV) ? IntervalMatrix(Ep*B_) : IntervalMatrix(B_*Ep);
56
57 // We want the presence of non-invertible matrices to
58 // result in coefficients of the form [-oo,+oo].
59 if (mrad==oo) {
60 for (Index c=0;c<N;c++) {
61 for (Index r=0;r<N;r++) {
62 if (Ep(r,c).is_unbounded()) {
63 for (Index k=0;k<N;k++) {
64 if constexpr(O == LEFT_INV)
65 res(r,k) = Interval();
66 else
67 res(k,c) = Interval();
68 }
69 }
70 }
71 }
72 }
73 return res;
74 }

◆ inverse_enclosure()

template<typename OtherDerived>
IntervalMatrix codac2::inverse_enclosure ( const Eigen::MatrixBase< OtherDerived > & A)
inline

Enclosure of the inverse of a (non-singular) matrix expression, possibly an interval matrix.

Precondition
\(\mathbf{A}\) is a square matrix.
Parameters
AA matrix expression, possibly interval.
Returns
The enclosure of the inverse. Can have \((-\infty,\infty)\) coefficients if \(\mathbf{A}\) is singular or almost singular, if the inversion "failed".
88 {
89 assert_release(A.is_squared());
90 Index N = A.rows();
91
92 if constexpr(std::is_same_v<typename OtherDerived::Scalar,Interval>)
94 (A.mid()).fullPivLu().solve(Matrix::Identity(N,N)));
95
96 else
98 A.fullPivLu().solve(Matrix::Identity(N,N)));
99 }
IntervalMatrix inverse_correction(const Eigen::MatrixBase< OtherDerived > &A, const Eigen::MatrixBase< OtherDerived_ > &B)
Correct the approximation of the inverse of a square matrix by providing a reliable enclosure .
Definition codac2_inversion.h:35

◆ infinite_sum_enclosure()

IntervalMatrix codac2::infinite_sum_enclosure ( const IntervalMatrix & A,
double & mrad )

Compute an upper bound of \(\left([\mathbf{A}]+[\mathbf{A}]^2+[\mathbf{A}]^3+\dots\right)\), with \([\mathbf{A}]\) a matrix of intervals as an "error term" (uses only bounds on coefficients).

The function also returns mrad, which gives an idea of the magnification of the matrix during calculation. In particular, if mrad = \(\infty\), then the inversion calculation (e.g., performed by Eigen) has somehow failed and some coefficients of the output interval matrix are \([-\infty,\infty]\).

Precondition
\([\mathbf{A}]\) is a square matrix.
Parameters
AA matrix of intervals (supposed around \(\mathbf{0}\)).
mradThe maximum radius of the result added (output argument).
Returns
The sum enclosure. May be unbounded.