codac 1.5.6
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 IntervalMatrix infinite_sum_enclosure(const IntervalMatrix& A, double &mrad);
35
46 template<LeftOrRightInv O=LEFT_INV,typename OtherDerived,typename OtherDerived_>
47 inline IntervalMatrix inverse_correction(const Eigen::MatrixBase<OtherDerived>& A, const Eigen::MatrixBase<OtherDerived_>& B)
48 {
49 assert_release(A.is_squared());
50 assert_release(B.is_squared());
51
52 auto A_ = A.template cast<Interval>();
53 auto B_ = B.template cast<Interval>();
54
55 Index N = A_.rows();
56 assert_release(N==B_.rows());
57
58 auto Id = IntervalMatrix::Identity(N,N);
59 auto erMat = [&]() { if constexpr(O == LEFT_INV) return -B_*A_+Id; else return -A_*B_+Id; }();
60
61 double mrad=0.0;
62 IntervalMatrix E = infinite_sum_enclosure(erMat,mrad);
63 IntervalMatrix Ep = Id+erMat*(Id+E);
64 /* one could use several iterations here, either
65 using mrad, or directly */
66
67 auto res = (O == LEFT_INV) ? IntervalMatrix(Ep*B_) : IntervalMatrix(B_*Ep);
68
69 // We want the presence of non-invertible matrices to
70 // result in coefficients of the form [-oo,+oo].
71 if (mrad==oo) {
72 for (Index c=0;c<N;c++) {
73 for (Index r=0;r<N;r++) {
74 if (Ep(r,c).is_unbounded()) {
75 for (Index k=0;k<N;k++) {
76 if constexpr(O == LEFT_INV)
77 res(r,k) = Interval();
78 else
79 res(k,c) = Interval();
80 }
81 }
82 }
83 }
84 }
85 return res;
86 }
87
96 template<typename OtherDerived>
97 inline IntervalMatrix inverse_enclosure(const Eigen::MatrixBase<OtherDerived>& A)
98 {
99 assert_release(A.is_squared());
100 Index N=A.rows();
102 A.fullPivLu().solve(Matrix::Identity(N,N)));
103 }
104
105
114 IntervalMatrix inverse_enclosure(const IntervalMatrix &A);
115}
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.
Definition codac2_inversion.h:97
IntervalMatrix inverse_correction(const Eigen::MatrixBase< OtherDerived > &A, const Eigen::MatrixBase< OtherDerived_ > &B)
Correct the approximate inverse of a matrix.
Definition codac2_inversion.h:47
IntervalMatrix infinite_sum_enclosure(const IntervalMatrix &A, double &mrad)
Compute an upper bound of A+A^2+A^3+..., with A a matrix of intervals as an "error term" (use only bo...