58 Error(
"TDecompQRH(Int_t,Int_t",
"matrix rows should be >= columns");
62 fQ.ResizeTo(nrows,ncols);
63 fR.ResizeTo(ncols,ncols);
78 const Int_t nrows = row_upb-row_lwb+1;
79 const Int_t ncols = col_upb-col_lwb+1;
82 Error(
"TDecompQRH(Int_t,Int_t,Int_t,Int_t",
"matrix rows should be >= columns");
89 fQ.ResizeTo(nrows,ncols);
90 fR.ResizeTo(ncols,ncols);
106 if (
a.GetNrows() <
a.GetNcols()) {
107 Error(
"TDecompQRH(const TMatrixD &",
"matrix rows should be >= columns");
119 const Int_t nRow =
a.GetNrows();
120 const Int_t nCol =
a.GetNcols();
122 fQ.ResizeTo(nRow,nCol);
123 memcpy(
fQ.GetMatrixArray(),
a.GetMatrixArray(),nRow*nCol*
sizeof(
Double_t));
124 fR.ResizeTo(nCol,nCol);
155 Error(
"Decompose()",
"Matrix has not been set");
167 else diagR.
Use(nCol,work);
171 const Int_t ic = (
i < nCol) ?
i : nCol;
172 for (
Int_t j = ic ; j < nCol; j++)
191 const Int_t nRow =
q.GetNrows();
192 const Int_t nCol =
q.GetNcols();
194 const Int_t n = (nRow <= nCol) ? nRow-1 : nCol;
196 for (
Int_t k = 0 ; k <
n ; k++) {
200 diagR(k) = qc_k(k)-up(k);
203 for (
Int_t j = k+1; j < nCol; j++) {
211 diagR(nRow-1) =
q(nRow-1,nRow-1);
227 if (
a.GetNrows() <
a.GetNcols()) {
228 Error(
"TDecompQRH(const TMatrixD &",
"matrix rows should be >= columns");
237 const Int_t nRow =
a.GetNrows();
238 const Int_t nCol =
a.GetNcols();
240 fQ.ResizeTo(nRow,nCol);
241 memcpy(
fQ.GetMatrixArray(),
a.GetMatrixArray(),nRow*nCol*
sizeof(
Double_t));
242 fR.ResizeTo(nCol,nCol);
260 Error(
"Solve()",
"Matrix is singular");
265 Error(
"Solve()",
"Decomposition failed");
270 if (
fQ.GetNrows() !=
b.GetNrows() ||
fQ.GetRowLwb() !=
b.GetLwb()) {
271 Error(
"Solve(TVectorD &",
"vector and matrix incompatible");
275 const Int_t nQRow =
fQ.GetNrows();
276 const Int_t nQCol =
fQ.GetNcols();
279 const Int_t nQ = (nQRow <= nQCol) ? nQRow-1 : nQCol;
280 for (
Int_t k = 0; k < nQ; k++) {
285 const Int_t nRCol =
fR.GetNcols();
291 for (
Int_t i = nRCol-1;
i >= 0;
i--) {
292 const Int_t off_i =
i*nRCol;
294 for (
Int_t j =
i+1; j < nRCol; j++)
295 r -= pR[off_i+j]*pb[j];
298 Error(
"Solve(TVectorD &)",
"R[%d,%d]=%.4e < %.4e",
i,
i,pR[off_i+
i],
fTol);
301 pb[
i] =
r/pR[off_i+
i];
316 Error(
"Solve()",
"Matrix is singular");
321 Error(
"Solve()",
"Decomposition failed");
326 if (
fQ.GetNrows() !=
b->GetNrows() ||
fQ.GetRowLwb() !=
b->GetRowLwb())
328 Error(
"Solve(TMatrixDColumn &",
"vector and matrix incompatible");
332 const Int_t nQRow =
fQ.GetNrows();
333 const Int_t nQCol =
fQ.GetNcols();
336 const Int_t nQ = (nQRow <= nQCol) ? nQRow-1 : nQCol;
337 for (
Int_t k = 0; k < nQ; k++) {
342 const Int_t nRCol =
fR.GetNcols();
349 for (
Int_t i = nRCol-1;
i >= 0;
i--) {
350 const Int_t off_i =
i*nRCol;
351 const Int_t off_i2 =
i*inc;
353 for (
Int_t j =
i+1; j < nRCol; j++)
354 r -= pR[off_i+j]*pcb[j*inc];
357 Error(
"Solve(TMatrixDColumn &)",
"R[%d,%d]=%.4e < %.4e",
i,
i,pR[off_i+
i],
fTol);
360 pcb[off_i2] =
r/pR[off_i+
i];
374 Error(
"TransSolve()",
"Matrix is singular");
379 Error(
"TransSolve()",
"Decomposition failed");
384 if (
fQ.GetNrows() !=
fQ.GetNcols() ||
fQ.GetRowLwb() !=
fQ.GetColLwb()) {
385 Error(
"TransSolve(TVectorD &",
"matrix should be square");
389 if (
fR.GetNrows() !=
b.GetNrows() ||
fR.GetRowLwb() !=
b.GetLwb()) {
390 Error(
"TransSolve(TVectorD &",
"vector and matrix incompatible");
397 const Int_t nRCol =
fR.GetNcols();
401 const Int_t off_i =
i*nRCol;
403 for (
Int_t j = 0; j <
i; j++) {
404 const Int_t off_j = j*nRCol;
405 r -= pR[off_j+
i]*pb[j];
409 Error(
"TransSolve(TVectorD &)",
"R[%d,%d]=%.4e < %.4e",
i,
i,pR[off_i+
i],
fTol);
412 pb[
i] =
r/pR[off_i+
i];
415 const Int_t nQRow =
fQ.GetNrows();
418 for (
Int_t k = nQRow-1; k >= 0; k--) {
435 Error(
"TransSolve()",
"Matrix is singular");
440 Error(
"TransSolve()",
"Decomposition failed");
445 if (
fQ.GetNrows() !=
fQ.GetNcols() ||
fQ.GetRowLwb() !=
fQ.GetColLwb()) {
446 Error(
"TransSolve(TMatrixDColumn &",
"matrix should be square");
450 if (
fR.GetNrows() !=
b->GetNrows() ||
fR.GetRowLwb() !=
b->GetRowLwb()) {
451 Error(
"TransSolve(TMatrixDColumn &",
"vector and matrix incompatible");
459 const Int_t nRCol =
fR.GetNcols();
463 const Int_t off_i =
i*nRCol;
464 const Int_t off_i2 =
i*inc;
466 for (
Int_t j = 0; j <
i; j++) {
467 const Int_t off_j = j*nRCol;
468 r -= pR[off_j+
i]*pcb[j*inc];
472 Error(
"TransSolve(TMatrixDColumn &)",
"R[%d,%d]=%.4e < %.4e",
i,
i,pR[off_i+
i],
fTol);
475 pcb[off_i2] =
r/pR[off_i+
i];
478 const Int_t nQRow =
fQ.GetNrows();
481 for (
Int_t k = nQRow-1; k >= 0; k--) {
526 for (
int i = 0;
i < nCol; ++
i)
531 for (
int j = 0; j < nCol; ++j) {
533 int nQRow =
fQ.GetNrows();
534 for (
Int_t k = nQRow - 1; k >= 0; k--) {
551 Error(
"Invert(TMatrixD &",
"Input matrix has wrong shape");
595 if (
this != &source) {
597 fQ.ResizeTo(source.
fQ);
598 fR.ResizeTo(source.
fR);
600 fW.ResizeTo(source.
fW);
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.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void w
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
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*TMath::Power(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*TMath::Power(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...
const TMatrixTBase< Element > * GetMatrix() const
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.
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.
void inv(rsa_NUMBER *, rsa_NUMBER *, rsa_NUMBER *)