Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
abs_inverse.h File Reference

Go to the source code of this file.

Macros

#define ALWAYS_USE_TEMPLATE_PAR_AS_FUN_PAR
 

Functions

template<class M , class X >
abstract_determinant (M &mi, long q, X)
 

Macro Definition Documentation

◆ ALWAYS_USE_TEMPLATE_PAR_AS_FUN_PAR

#define ALWAYS_USE_TEMPLATE_PAR_AS_FUN_PAR

Definition at line 95 of file abs_inverse.h.

Function Documentation

◆ abstract_determinant()

template<class M , class X >
X abstract_determinant ( M &  mi,
long  q,
 
)

Definition at line 104 of file abs_inverse.h.

116 {
117 if (q == 1) {
118 return mi.ac(0, 0);
119 } else if (q == 2) {
120 return mi.ac(0, 0) * mi.ac(1, 1) - mi.ac(0, 1) * mi.ac(1, 0);
121 } else if (q == 3) {
122 return mi.ac(0, 0) * mi.ac(1, 1) * mi.ac(2, 2) +
123 mi.ac(0, 2) * mi.ac(1, 0) * mi.ac(2, 1) +
124 mi.ac(0, 1) * mi.ac(1, 2) * mi.ac(2, 0) -
125 mi.ac(0, 2) * mi.ac(1, 1) * mi.ac(2, 0) -
126 mi.ac(0, 0) * mi.ac(1, 2) * mi.ac(2, 1) -
127 mi.ac(0, 1) * mi.ac(1, 0) * mi.ac(2, 2);
128 } else {
129 long nr, nr1, nc;
130 X koef = 1;
131 for (nr = 0; nr < q; nr++) {
132 long nmax = 0;
133 double d = 0;
134 for (nr1 = nr; nr1 < q; nr1++) {
135 if (fabs(mi.ac(nr1, nr)) > d) {
136 d = fabs(mi.ac(nr1, nr));
137 nmax = nr1;
138 }
139 }
140 //mcout<<"d="<<d<<'\n';
141 //mcout<<"nmax="<<nmax<<'\n';
142 if (d == 0) {
143 //serr = 1;
144 return koef * mi.ac(nmax, nr);
145 }
146 if (nmax > nr) {
147 for (nc = nr; nc < q; nc++) {
148 X t(mi.ac(nr, nc));
149 mi.ac(nr, nc) = mi.ac(nmax, nc);
150 mi.ac(nmax, nc) = t;
151 }
152 koef *= -1; // trancposition of rows: determinant changes sign
153 }
154 X t = mi.ac(nr, nr);
155 for (nr1 = nr + 1; nr1 < q; nr1++) {
156 X k(mi.ac(nr1, nr) / t);
157 //mcout<<"nr1="<<nr1<<" nr="<<nr<<'\n';
158 //mcout<<"k="<<k<<'\n';
159 for (nc = nr; nc < q; nc++) {
160 mi.ac(nr1, nc) -= k * mi.ac(nr, nc);
161 } // add elements of another row: the main value of
162 // determinant is not affected (proven in linear algebra)
163 // But the resolution gets worser.
164 }
165 for (nc = nr; nc < q; nc++) {
166 mi.ac(nr, nc) /= t;
167 }
168 koef *= t;
169 }
170 return koef;
171 }
172}
DoubleAc fabs(const DoubleAc &f)
Definition: DoubleAc.h:616

Referenced by determinant_DynArr().