codac 2.0.0
Loading...
Searching...
No Matches
codac2_inversion.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <ostream>
13#include "codac2_Matrix.h"
15
16namespace codac2
17{
18 enum LeftOrRightInv { LEFT_INV, RIGHT_INV };
19
34 template<LeftOrRightInv O=LEFT_INV,typename OtherDerived,typename OtherDerived_>
35 inline IntervalMatrix inverse_correction(const Eigen::MatrixBase<OtherDerived>& A, const Eigen::MatrixBase<OtherDerived_>& B)
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 }
75
86 template<typename OtherDerived>
87 inline IntervalMatrix inverse_enclosure(const Eigen::MatrixBase<OtherDerived>& A)
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 }
100
116 IntervalMatrix infinite_sum_enclosure(const IntervalMatrix& A, double& mrad);
117}
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
IntervalMatrix inverse_enclosure(const Eigen::MatrixBase< OtherDerived > &A)
Enclosure of the inverse of a (non-singular) matrix expression, possibly an interval matrix.
Definition codac2_inversion.h:87
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
IntervalMatrix infinite_sum_enclosure(const IntervalMatrix &A, double &mrad)
Compute an upper bound of , with a matrix of intervals as an "error term" (uses only bounds on coeff...