47 Error(
"TDecompQRH(Int_t,Int_t",
"matrix rows should be >= columns");
51 fQ.ResizeTo(nrows,ncols);
52 fR.ResizeTo(ncols,ncols);
67 const Int_t nrows = row_upb-row_lwb+1;
68 const Int_t ncols = col_upb-col_lwb+1;
71 Error(
"TDecompQRH(Int_t,Int_t,Int_t,Int_t",
"matrix rows should be >= columns");
96 Error(
"TDecompQRH(const TMatrixD &",
"matrix rows should be >= columns");
144 Error(
"Decompose()",
"Matrix has not been set");
156 else diagR.
Use(nCol,work);
159 for (
Int_t i = 0; i < nRow; i++) {
160 const Int_t ic = (i < nCol) ? i : nCol;
161 for (
Int_t j = ic ; j < nCol; j++)
183 const Int_t n = (nRow <= nCol) ? nRow-1 : nCol;
185 for (
Int_t k = 0 ; k <
n ; k++) {
189 diagR(k) = qc_k(k)-up(k);
192 for (
Int_t j = k+1; j < nCol; j++) {
200 diagR(nRow-1) =
q(nRow-1,nRow-1);
217 Error(
"TDecompQRH(const TMatrixD &",
"matrix rows should be >= columns");
249 Error(
"Solve()",
"Matrix is singular");
254 Error(
"Solve()",
"Decomposition failed");
260 Error(
"Solve(TVectorD &",
"vector and matrix incompatible");
268 const Int_t nQ = (nQRow <= nQCol) ? nQRow-1 : nQCol;
269 for (
Int_t k = 0; k < nQ; k++) {
280 for (
Int_t i = nRCol-1; i >= 0; i--) {
281 const Int_t off_i = i*nRCol;
283 for (
Int_t j = i+1; j < nRCol; j++)
284 r -= pR[off_i+j]*pb[j];
287 Error(
"Solve(TVectorD &)",
"R[%d,%d]=%.4e < %.4e",i,i,pR[off_i+i],
fTol);
290 pb[i] = r/pR[off_i+i];
305 Error(
"Solve()",
"Matrix is singular");
310 Error(
"Solve()",
"Decomposition failed");
317 Error(
"Solve(TMatrixDColumn &",
"vector and matrix incompatible");
325 const Int_t nQ = (nQRow <= nQCol) ? nQRow-1 : nQCol;
326 for (
Int_t k = 0; k < nQ; k++) {
338 for (
Int_t i = nRCol-1; i >= 0; i--) {
339 const Int_t off_i = i*nRCol;
340 const Int_t off_i2 = i*inc;
342 for (
Int_t j = i+1; j < nRCol; j++)
343 r -= pR[off_i+j]*pcb[j*inc];
346 Error(
"Solve(TMatrixDColumn &)",
"R[%d,%d]=%.4e < %.4e",i,i,pR[off_i+i],
fTol);
349 pcb[off_i2] = r/pR[off_i+i];
363 Error(
"TransSolve()",
"Matrix is singular");
368 Error(
"TransSolve()",
"Decomposition failed");
374 Error(
"TransSolve(TVectorD &",
"matrix should be square");
379 Error(
"TransSolve(TVectorD &",
"vector and matrix incompatible");
389 for (
Int_t i = 0; i < nRCol; i++) {
390 const Int_t off_i = i*nRCol;
392 for (
Int_t j = 0; j < i; j++) {
393 const Int_t off_j = j*nRCol;
394 r -= pR[off_j+i]*pb[j];
398 Error(
"TransSolve(TVectorD &)",
"R[%d,%d]=%.4e < %.4e",i,i,pR[off_i+i],
fTol);
401 pb[i] = r/pR[off_i+i];
407 for (
Int_t k = nQRow-1; k >= 0; k--) {
424 Error(
"TransSolve()",
"Matrix is singular");
429 Error(
"TransSolve()",
"Decomposition failed");
435 Error(
"TransSolve(TMatrixDColumn &",
"matrix should be square");
440 Error(
"TransSolve(TMatrixDColumn &",
"vector and matrix incompatible");
451 for (
Int_t i = 0; i < nRCol; i++) {
452 const Int_t off_i = i*nRCol;
453 const Int_t off_i2 = i*inc;
455 for (
Int_t j = 0; j < i; j++) {
456 const Int_t off_j = j*nRCol;
457 r -= pR[off_j+i]*pcb[j*inc];
461 Error(
"TransSolve(TMatrixDColumn &)",
"R[%d,%d]=%.4e < %.4e",i,i,pR[off_i+i],
fTol);
464 pcb[off_i2] = r/pR[off_i+i];
470 for (
Int_t k = nQRow-1; k >= 0; k--) {
508 Error(
"Invert(TMatrixD &",
"Input matrix has wrong shape");
552 if (
this != &source) {
virtual TMatrixTBase< Element > & UnitMatrix()
Make a unit matrix (matrix need not be a square one).
ClassImp(TDecompQRH) TDecompQRH
Constructor for (nrows x ncols) matrix.
virtual TMatrixTBase< Element > & Shift(Int_t row_shift, Int_t col_shift)
Shift the row index by adding row_shift and the column index by adding col_shift, respectively...
TVectorT< Element > & ResizeTo(Int_t lwb, Int_t upb)
Resize the vector to [lwb:upb] .
virtual Bool_t MultiSolve(TMatrixD &B)
Solve set of equations with RHS in columns of B.
void Print(Option_t *opt="") const
Print the class members.
void Print(Option_t *opt="") const
Print class members.
double inv(double x)
For comparisons.
TMatrixTColumn_const< Double_t > TMatrixDColumn_const
virtual TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1)
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
Bool_t DefHouseHolder(const TVectorD &vc, Int_t lp, Int_t l, Double_t &up, Double_t &b, Double_t tol=0.0)
Define a Householder-transformation through the parameters up and b .
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
TVectorT< Element > & Use(Int_t lwb, Int_t upb, Element *data)
Use the array data to fill the vector lwb..upb].
TDecompBase & operator=(const TDecompBase &source)
Assignment operator.
TDecompQRH & operator=(const TDecompQRH &source)
Assignment operator.
static Bool_t QRH(TMatrixD &q, TVectorD &diagR, TVectorD &up, TVectorD &w, Double_t tol)
Decomposition function .
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
void Error(const char *location, const char *msgfmt,...)
Element * GetMatrixArray()
void Print(Option_t *name="") const
Print the matrix as a table of elements.
void Print(Option_t *option="") const
Print the vector as a list of elements.
virtual Bool_t Decompose()
QR decomposition of matrix a by Householder transformations, see Golub & Loan first edition p41 & Sec...
virtual Bool_t Solve(TVectorD &b)
Solve Ax=b assuming the QR form of A is stored in fR,fQ and fW, but assume b has not been transformed...
void ApplyHouseHolder(const TVectorD &vc, Double_t up, Double_t b, Int_t lp, Int_t l, TMatrixDRow &cr)
Apply Householder-transformation.
Bool_t TestBit(UInt_t f) const
virtual const Element * GetMatrixArray() const
virtual void Det(Double_t &d1, Double_t &d2)
This routine calculates the absolute (!) value of the determinant |det| = d1*TMath::Power(2.,d2)
const TMatrixTBase< Element > * GetMatrix() const
virtual Int_t GetNrows() const
virtual Bool_t TransSolve(TVectorD &b)
Solve A^T x=b assuming the QR form of A is stored in fR,fQ and fW, but assume b has not been transfor...
virtual void Det(Double_t &d1, Double_t &d2)
Matrix determinant det = d1*TMath::Power(2.,d2)
TMatrixTColumn< Double_t > TMatrixDColumn
virtual Int_t GetNcols() const
virtual void SetMatrix(const TMatrixD &a)
Set matrix to be decomposed.