//$$ cholesky.cpp cholesky decomposition // Copyright (C) 1991,2,3,4: R B Davies #define WANT_MATH //#define WANT_STREAM #include "include.h" #include "newmat.h" #ifdef use_namespace namespace NEWMAT { #endif #ifdef DO_REPORT #define REPORT { static ExeCounter ExeCount(__LINE__,14); ++ExeCount; } #else #define REPORT {} #endif /********* Cholesky decomposition of a positive definite matrix *************/ // Suppose S is symmetrix and positive definite. Then there exists a unique // lower triangular matrix L such that L L.t() = S; inline Real square(Real x) { return x*x; } ReturnMatrix Cholesky(const SymmetricMatrix& S) { REPORT Tracer trace("Cholesky"); int nr = S.Nrows(); LowerTriangularMatrix T(nr); Real* s = S.Store(); Real* t = T.Store(); Real* ti = t; for (int i=0; i