45 const Int_t nrows = row_upb-row_lwb+1;
48 fU.
ResizeTo(row_lwb,row_lwb+nrows-1,row_lwb,row_lwb+nrows-1);
77 if (
a.GetNrows() !=
a.GetNcols() ||
a.GetRowLwb() !=
a.GetColLwb()) {
78 Error(
"TDecompChol(const TMatrixD &",
"matrix should be square");
111 Error(
"Decompose()",
"Matrix has not been set");
118 for (icol = 0; icol <
n; icol++) {
119 const Int_t rowOff = icol*
n;
123 for (irow = 0; irow < icol; irow++) {
124 const Int_t pos_ij = irow*
n+icol;
125 ujj -= pU[pos_ij]*pU[pos_ij];
128 Error(
"Decompose()",
"matrix not positive definite");
132 pU[rowOff+icol] = ujj;
136 for (j = icol+1; j <
n; j++) {
137 for (i = 0; i < icol; i++) {
138 const Int_t rowOff2 = i*
n;
139 pU[rowOff+j] -= pU[rowOff2+j]*pU[rowOff2+icol];
142 for (j = icol+1; j <
n; j++)
143 pU[rowOff + j] *= inv_ujj;
147 for (irow = 0; irow <
n; irow++) {
148 const Int_t rowOff = irow*
n;
149 for (icol = 0; icol < irow; icol++)
150 pU[rowOff+icol] = 0.;
164 Error(
"GetMatrix()",
"Matrix is singular");
169 Error(
"GetMatrix()",
"Decomposition failed");
185 if (
a.GetNrows() !=
a.GetNcols() ||
a.GetRowLwb() !=
a.GetColLwb()) {
186 Error(
"SetMatrix(const TMatrixDSym &",
"matrix should be square");
208 Error(
"Solve()",
"Matrix is singular");
213 Error(
"Solve()",
"Decomposition failed");
219 Error(
"Solve(TVectorD &",
"vector and matrix incompatible");
230 for (i = 0; i <
n; i++) {
232 if (pU[off_i+i] <
fTol)
234 Error(
"Solve(TVectorD &b)",
"u[%d,%d]=%.4e < %.4e",i,i,pU[off_i+i],
fTol);
238 for (
Int_t j = 0; j < i; j++) {
240 r -= pU[off_j+i]*pb[j];
242 pb[i] =
r/pU[off_i+i];
246 for (i =
n-1; i >= 0; i--) {
249 for (
Int_t j = i+1; j <
n; j++)
250 r -= pU[off_i+j]*pb[j];
251 pb[i] =
r/pU[off_i+i];
267 Error(
"Solve()",
"Matrix is singular");
272 Error(
"Solve()",
"Decomposition failed");
279 Error(
"Solve(TMatrixDColumn &cb",
"vector and matrix incompatible");
291 for (i = 0; i <
n; i++) {
293 const Int_t off_i2 = i*inc;
294 if (pU[off_i+i] <
fTol)
296 Error(
"Solve(TMatrixDColumn &cb)",
"u[%d,%d]=%.4e < %.4e",i,i,pU[off_i+i],
fTol);
300 for (
Int_t j = 0; j < i; j++) {
302 r -= pU[off_j+i]*pcb[j*inc];
304 pcb[off_i2] =
r/pU[off_i+i];
308 for (i =
n-1; i >= 0; i--) {
310 const Int_t off_i2 = i*inc;
312 for (
Int_t j = i+1; j <
n; j++)
313 r -= pU[off_i+j]*pcb[j*inc];
314 pcb[off_i2] =
r/pU[off_i+i];
345 Error(
"Invert(TMatrixDSym &",
"Input matrix has wrong shape");
351 const Int_t colLwb =
inv.GetColLwb();
352 const Int_t colUpb =
inv.GetColUpb();
354 for (
Int_t icol = colLwb; icol <= colUpb && status; icol++) {
391 if (
this != &source) {
423 ::Error(
"NormalEqn",
"vectors b and std are not compatible");
431 mBw(irow) /= std(irow);
TVectorD NormalEqn(const TMatrixD &A, const TVectorD &b)
Solve min {(A .
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
TMatrixTSym< Double_t > TMatrixDSym
TMatrixTRow< Double_t > TMatrixDRow
TMatrixT< Double_t > TMatrixD
TVectorT< Double_t > TVectorD
Decomposition Base class.
virtual Bool_t MultiSolve(TMatrixD &B)
Solve set of equations with RHS in columns of B.
TDecompBase & operator=(const TDecompBase &source)
Assignment operator.
void Print(Option_t *opt="") const override
Print class members.
virtual void Det(Double_t &d1, Double_t &d2)
Matrix determinant det = d1*TMath::Power(2.,d2)
Cholesky Decomposition class.
void Print(Option_t *opt="") const override
Print class members .
Bool_t Decompose() override
Matrix A is decomposed in component U so that A = U^T * U If the decomposition succeeds,...
Int_t GetNrows() const override
virtual void SetMatrix(const TMatrixDSym &a)
Set the matrix to be decomposed, decomposition status is reset.
Bool_t Solve(TVectorD &b) override
Solve equations Ax=b assuming A has been factored by Cholesky.
TDecompChol & operator=(const TDecompChol &source)
Assignment operator.
const TMatrixDSym GetMatrix()
Reconstruct the original matrix using the decomposition parts.
void Det(Double_t &d1, Double_t &d2) override
Matrix determinant det = d1*TMath::Power(2.,d2) is square of diagProd of cholesky factor.
void Print(Option_t *name="") const override
Print the matrix as a table of elements.
const TMatrixTBase< Element > * GetMatrix() const
const Element * GetMatrixArray() const override
TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1) override
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Double_t Sqrt(Double_t x)
Returns the square root of x.
Bool_t AreCompatible(const TMatrixTBase< Element1 > &m1, const TMatrixTBase< Element2 > &m2, Int_t verbose=0)
Check that matrice sm1 and m2 areboth valid and have identical shapes .
void inv(rsa_NUMBER *, rsa_NUMBER *, rsa_NUMBER *)