/// \ingroup newmat ///@{ /// \file hholder.cpp /// QR related decompositions /// QRZ, QRZT decompositions /// QR update and extend orthogonal functions // Copyright (C) 1991,2,3,4: R B Davies #define WANT_MATH //#define WANT_STREAM #include "include.h" #include "newmatap.h" #ifdef use_namespace namespace NEWMAT { #endif #ifdef DO_REPORT #define REPORT { static ExeCounter ExeCount(__LINE__,16); ++ExeCount; } #else #define REPORT {} #endif /*************************** QR decompositions ***************************/ inline Real square(Real x) { return x*x; } void QRZT(Matrix& X, LowerTriangularMatrix& L) { REPORT Tracer et("QRZT(1)"); int n = X.Ncols(); int s = X.Nrows(); L.resize(s); if (n == 0 || s == 0) { L = 0.0; return; } Real* xi = X.Store(); int k; for (int i=0; i nr) Throw(IncompatibleDimensionsException(A)); if (n > nc) Throw(IncompatibleDimensionsException(A)); ColumnVector SSR; { Matrix A1 = A.Columns(1,n); SSR = A1.sum_square_rows(); } for (int i = n; i < nc; ++i) { // pick row with smallest SSQ int k; SSR.minimum1(k); // orthogonalise column with 1 at element k, 0 elsewhere // next line is rather inefficient ColumnVector X = - A.Columns(1, i) * A.SubMatrix(k, k, 1, i).t(); X(k) += 1.0; // normalise X /= sqrt(X.SumSquare()); // update row sums of squares for (k = 1; k <= nr; ++k) SSR(k) += square(X(k)); // load new column into matrix A.Column(i+1) = X; } } #ifdef use_namespace } #endif ///@}