57 Error(
"TDecompQRH(Int_t,Int_t",
"matrix rows should be >= columns");
61 fQ.ResizeTo(nrows,ncols);
62 fR.ResizeTo(ncols,ncols);
77 const Int_t nrows = row_upb-row_lwb+1;
78 const Int_t ncols = col_upb-col_lwb+1;
81 Error(
"TDecompQRH(Int_t,Int_t,Int_t,Int_t",
"matrix rows should be >= columns");
88 fQ.ResizeTo(nrows,ncols);
89 fR.ResizeTo(ncols,ncols);
105 if (
a.GetNrows() <
a.GetNcols()) {
106 Error(
"TDecompQRH(const TMatrixD &",
"matrix rows should be >= columns");
118 const Int_t nRow =
a.GetNrows();
119 const Int_t nCol =
a.GetNcols();
121 fQ.ResizeTo(nRow,nCol);
122 memcpy(
fQ.GetMatrixArray(),
a.GetMatrixArray(),nRow*nCol*
sizeof(
Double_t));
123 fR.ResizeTo(nCol,nCol);
154 Error(
"Decompose()",
"Matrix has not been set");
166 else diagR.
Use(nCol,work);
169 for (
Int_t i = 0; i < nRow; i++) {
170 const Int_t ic = (i < nCol) ? i : nCol;
171 for (
Int_t j = ic ; j < nCol; j++)
190 const Int_t nRow =
q.GetNrows();
191 const Int_t nCol =
q.GetNcols();
193 const Int_t n = (nRow <= nCol) ? nRow-1 : nCol;
195 for (
Int_t k = 0 ; k <
n ; k++) {
199 diagR(k) = qc_k(k)-up(k);
202 for (
Int_t j = k+1; j < nCol; j++) {
210 diagR(nRow-1) =
q(nRow-1,nRow-1);
226 if (
a.GetNrows() <
a.GetNcols()) {
227 Error(
"TDecompQRH(const TMatrixD &",
"matrix rows should be >= columns");
236 const Int_t nRow =
a.GetNrows();
237 const Int_t nCol =
a.GetNcols();
239 fQ.ResizeTo(nRow,nCol);
240 memcpy(
fQ.GetMatrixArray(),
a.GetMatrixArray(),nRow*nCol*
sizeof(
Double_t));
241 fR.ResizeTo(nCol,nCol);
259 Error(
"Solve()",
"Matrix is singular");
264 Error(
"Solve()",
"Decomposition failed");
269 if (
fQ.GetNrows() !=
b.GetNrows() ||
fQ.GetRowLwb() !=
b.GetLwb()) {
270 Error(
"Solve(TVectorD &",
"vector and matrix incompatible");
274 const Int_t nQRow =
fQ.GetNrows();
275 const Int_t nQCol =
fQ.GetNcols();
278 const Int_t nQ = (nQRow <= nQCol) ? nQRow-1 : nQCol;
279 for (
Int_t k = 0; k < nQ; k++) {
284 const Int_t nRCol =
fR.GetNcols();
290 for (
Int_t i = nRCol-1; i >= 0; i--) {
291 const Int_t off_i = i*nRCol;
293 for (
Int_t j = i+1; j < nRCol; j++)
294 r -= pR[off_i+j]*pb[j];
297 Error(
"Solve(TVectorD &)",
"R[%d,%d]=%.4e < %.4e",i,i,pR[off_i+i],
fTol);
300 pb[i] =
r/pR[off_i+i];
315 Error(
"Solve()",
"Matrix is singular");
320 Error(
"Solve()",
"Decomposition failed");
325 if (
fQ.GetNrows() !=
b->GetNrows() ||
fQ.GetRowLwb() !=
b->GetRowLwb())
327 Error(
"Solve(TMatrixDColumn &",
"vector and matrix incompatible");
331 const Int_t nQRow =
fQ.GetNrows();
332 const Int_t nQCol =
fQ.GetNcols();
335 const Int_t nQ = (nQRow <= nQCol) ? nQRow-1 : nQCol;
336 for (
Int_t k = 0; k < nQ; k++) {
341 const Int_t nRCol =
fR.GetNcols();
348 for (
Int_t i = nRCol-1; i >= 0; i--) {
349 const Int_t off_i = i*nRCol;
350 const Int_t off_i2 = i*inc;
352 for (
Int_t j = i+1; j < nRCol; j++)
353 r -= pR[off_i+j]*pcb[j*inc];
356 Error(
"Solve(TMatrixDColumn &)",
"R[%d,%d]=%.4e < %.4e",i,i,pR[off_i+i],
fTol);
359 pcb[off_i2] =
r/pR[off_i+i];
373 Error(
"TransSolve()",
"Matrix is singular");
378 Error(
"TransSolve()",
"Decomposition failed");
383 if (
fQ.GetNrows() !=
fQ.GetNcols() ||
fQ.GetRowLwb() !=
fQ.GetColLwb()) {
384 Error(
"TransSolve(TVectorD &",
"matrix should be square");
388 if (
fR.GetNrows() !=
b.GetNrows() ||
fR.GetRowLwb() !=
b.GetLwb()) {
389 Error(
"TransSolve(TVectorD &",
"vector and matrix incompatible");
396 const Int_t nRCol =
fR.GetNcols();
399 for (
Int_t i = 0; i < nRCol; i++) {
400 const Int_t off_i = i*nRCol;
402 for (
Int_t j = 0; j < i; j++) {
403 const Int_t off_j = j*nRCol;
404 r -= pR[off_j+i]*pb[j];
408 Error(
"TransSolve(TVectorD &)",
"R[%d,%d]=%.4e < %.4e",i,i,pR[off_i+i],
fTol);
411 pb[i] =
r/pR[off_i+i];
414 const Int_t nQRow =
fQ.GetNrows();
417 for (
Int_t k = nQRow-1; k >= 0; k--) {
434 Error(
"TransSolve()",
"Matrix is singular");
439 Error(
"TransSolve()",
"Decomposition failed");
444 if (
fQ.GetNrows() !=
fQ.GetNcols() ||
fQ.GetRowLwb() !=
fQ.GetColLwb()) {
445 Error(
"TransSolve(TMatrixDColumn &",
"matrix should be square");
449 if (
fR.GetNrows() !=
b->GetNrows() ||
fR.GetRowLwb() !=
b->GetRowLwb()) {
450 Error(
"TransSolve(TMatrixDColumn &",
"vector and matrix incompatible");
458 const Int_t nRCol =
fR.GetNcols();
461 for (
Int_t i = 0; i < nRCol; i++) {
462 const Int_t off_i = i*nRCol;
463 const Int_t off_i2 = i*inc;
465 for (
Int_t j = 0; j < i; j++) {
466 const Int_t off_j = j*nRCol;
467 r -= pR[off_j+i]*pcb[j*inc];
471 Error(
"TransSolve(TMatrixDColumn &)",
"R[%d,%d]=%.4e < %.4e",i,i,pR[off_i+i],
fTol);
474 pcb[off_i2] =
r/pR[off_i+i];
477 const Int_t nQRow =
fQ.GetNrows();
480 for (
Int_t k = nQRow-1; k >= 0; k--) {
525 for (
int i = 0; i < nCol; ++i)
530 for (
int j = 0; j < nCol; ++j) {
532 int nQRow =
fQ.GetNrows();
533 for (
Int_t k = nQRow - 1; k >= 0; k--) {
550 Error(
"Invert(TMatrixD &",
"Input matrix has wrong shape");
594 if (
this != &source) {
596 fQ.ResizeTo(source.
fQ);
597 fR.ResizeTo(source.
fR);
599 fW.ResizeTo(source.
fW);
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).
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 ApplyHouseHolder(const TVectorD &vc, Double_t up, Double_t b, Int_t lp, Int_t l, TMatrixDRow &cr)
Apply Householder-transformation.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
TMatrixTBase< Double_t > TMatrixDBase
TMatrixTColumn_const< Double_t > TMatrixDColumn_const
TMatrixTDiag< Double_t > TMatrixDDiag
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).
virtual void SetMatrix(const TMatrixD &a)
Set matrix to be decomposed.
Bool_t Solve(TVectorD &b) override
Solve Ax=b assuming the QR form of A is stored in fR,fQ and fW, but assume b has not been transformed...
Int_t GetNrows() const override
void Print(Option_t *opt="") const override
Print the class members.
void Det(Double_t &d1, Double_t &d2) override
This routine calculates the absolute (!) value of the determinant |det| = d1*TMathPower(2....
TDecompQRH & operator=(const TDecompQRH &source)
Assignment operator.
TMatrixD GetOrthogonalMatrix() const
For a matrix A(m,n), return the OtrhogonalMatrix Q such as A = Q * R.
static Bool_t QRH(TMatrixD &q, TVectorD &diagR, TVectorD &up, TVectorD &w, Double_t tol)
Decomposition function .
Bool_t Decompose() override
QR decomposition of matrix a by Householder transformations, see Golub & Loan first edition p41 & Sec...
Int_t GetNcols() const override
Bool_t TransSolve(TVectorD &b) override
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 TMatrixTBase< Element > & UnitMatrix()
Make a unit matrix (matrix need not be a square one).
const TMatrixTBase< Element > * GetMatrix() const
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...
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.
TVectorT< Element > & ResizeTo(Int_t lwb, Int_t upb)
Resize the vector to [lwb:upb] .
TVectorT< Element > & Use(Int_t lwb, Int_t upb, Element *data)
Use the array data to fill the vector lwb..upb].
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.