36 fU.ResizeTo(nrows,nrows);
44 const Int_t nrows = row_upb-row_lwb+1;
47 fU.ResizeTo(row_lwb,row_lwb+nrows-1,row_lwb,row_lwb+nrows-1);
76 if (
a.GetNrows() !=
a.GetNcols() ||
a.GetRowLwb() !=
a.GetColLwb()) {
77 Error(
"TDecompChol(const TMatrixD &",
"matrix should be square");
110 Error(
"Decompose()",
"Matrix has not been set");
117 for (icol = 0; icol <
n; icol++) {
118 const Int_t rowOff = icol*
n;
122 for (irow = 0; irow < icol; irow++) {
123 const Int_t pos_ij = irow*
n+icol;
124 ujj -= pU[pos_ij]*pU[pos_ij];
127 Error(
"Decompose()",
"matrix not positive definite");
131 pU[rowOff+icol] = ujj;
135 for (j = icol+1; j <
n; j++) {
136 for (i = 0; i < icol; i++) {
137 const Int_t rowOff2 = i*
n;
138 pU[rowOff+j] -= pU[rowOff2+j]*pU[rowOff2+icol];
141 for (j = icol+1; j <
n; j++)
142 pU[rowOff + j] *= inv_ujj;
146 for (irow = 0; irow <
n; irow++) {
147 const Int_t rowOff = irow*
n;
148 for (icol = 0; icol < irow; icol++)
149 pU[rowOff+icol] = 0.;
163 Error(
"GetMatrix()",
"Matrix is singular");
168 Error(
"GetMatrix()",
"Decomposition failed");
184 if (
a.GetNrows() !=
a.GetNcols() ||
a.GetRowLwb() !=
a.GetColLwb()) {
185 Error(
"SetMatrix(const TMatrixDSym &",
"matrix should be square");
207 Error(
"Solve()",
"Matrix is singular");
212 Error(
"Solve()",
"Decomposition failed");
217 if (
fU.GetNrows() !=
b.GetNrows() ||
fU.GetRowLwb() !=
b.GetLwb()) {
218 Error(
"Solve(TVectorD &",
"vector and matrix incompatible");
229 for (i = 0; i <
n; i++) {
231 if (pU[off_i+i] <
fTol)
233 Error(
"Solve(TVectorD &b)",
"u[%d,%d]=%.4e < %.4e",i,i,pU[off_i+i],
fTol);
237 for (
Int_t j = 0; j < i; j++) {
239 r -= pU[off_j+i]*pb[j];
241 pb[i] =
r/pU[off_i+i];
245 for (i =
n-1; i >= 0; i--) {
248 for (
Int_t j = i+1; j <
n; j++)
249 r -= pU[off_i+j]*pb[j];
250 pb[i] =
r/pU[off_i+i];
266 Error(
"Solve()",
"Matrix is singular");
271 Error(
"Solve()",
"Decomposition failed");
276 if (
fU.GetNrows() !=
b->GetNrows() ||
fU.GetRowLwb() !=
b->GetRowLwb())
278 Error(
"Solve(TMatrixDColumn &cb",
"vector and matrix incompatible");
290 for (i = 0; i <
n; i++) {
292 const Int_t off_i2 = i*inc;
293 if (pU[off_i+i] <
fTol)
295 Error(
"Solve(TMatrixDColumn &cb)",
"u[%d,%d]=%.4e < %.4e",i,i,pU[off_i+i],
fTol);
299 for (
Int_t j = 0; j < i; j++) {
301 r -= pU[off_j+i]*pcb[j*inc];
303 pcb[off_i2] =
r/pU[off_i+i];
307 for (i =
n-1; i >= 0; i--) {
309 const Int_t off_i2 = i*inc;
311 for (
Int_t j = i+1; j <
n; j++)
312 r -= pU[off_i+j]*pcb[j*inc];
313 pcb[off_i2] =
r/pU[off_i+i];
344 Error(
"Invert(TMatrixDSym &",
"Input matrix has wrong shape");
353 for (
Int_t icol = colLwb; icol <= colUpb && status; icol++) {
390 if (
this != &source) {
392 fU.ResizeTo(source.
fU);
422 ::Error(
"NormalEqn",
"vectors b and std are not compatible");
430 mBw(irow) /= std(irow);
int Int_t
Signed integer 4 bytes (int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
const char Option_t
Option string (const char).
TVectorD NormalEqn(const TMatrixD &A, const TVectorD &b)
Solve min {(A .
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
TMatrixTBase< Double_t > TMatrixDBase
TMatrixTSym< Double_t > TMatrixDSym
TMatrixTRow< Double_t > TMatrixDRow
TMatrixTColumn< Double_t > TMatrixDColumn
TMatrixT< Double_t > TMatrixD
TVectorT< Double_t > TVectorD
virtual Bool_t MultiSolve(TMatrixD &B)
Solve set of equations with RHS in columns of B.
TDecompBase & operator=(const TDecompBase &source)
Assignment operator.
TDecompBase()
Default constructor.
void Print(Option_t *opt="") const override
Print class members.
virtual void Det(Double_t &d1, Double_t &d2)
Matrix determinant det = d1*TMathPower(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*TMathPower(2.,d2) is square of diagProd of cholesky factor.
virtual TMatrixTBase< Element > & UnitMatrix()
Make a unit matrix (matrix need not be a square one).
const TMatrixTBase< Element > * GetMatrix() const
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 .