/// <summary> /// Explicitly creates the upper triangular matrix U that resulted from the Cholesky factorization: A = transpose(U) * U, /// where A and U are n-by-n. /// This method is safe to use as the factorization data are copied (if necessary). However, it is inefficient if the /// generated matrix is only used once. /// </summary> public TriangularUpper GetFactorU() { // The factorization A = transpose(u) * D * u, u = unit upper triangular is stored. Thus U = sqrt(D) * u. // Since D is diagonal, we need to scale each column j of u by sqrt(D[j,j]). var upper = TriangularUpper.CreateZero(Order); for (int j = 0; j < Order; ++j) { int colheight = diagOffsets[j + 1] - diagOffsets[j] - 1; for (int t = 0; t < colheight + 1; ++t) { int i = j - t; upper[i, j] = values[diagOffsets[j] + t]; } } return(upper); }
/// <summary> /// Copies the upper triangular matrix U and diagonal matrix D that resulted from the Cholesky factorization: /// A = transpose(U) * D * U to a new <see cref="TriangularUpper"/> matrix. /// </summary> public (Vector diagonal, TriangularUpper upper) GetFactorsDU() //TODO: not sure if this is ever needed. { double[] diag = new double[Order]; var upper = TriangularUpper.CreateZero(Order); for (int j = 0; j < Order; ++j) { int diagOffset = diagOffsets[j]; int colTop = j - diagOffsets[j + 1] + diagOffset + 1; diag[j] = values[diagOffset]; upper[j, j] = 1.0; for (int i = j - 1; i >= colTop; --i) { int offset = diagOffset + j - i; upper[i, j] = values[offset]; } } return(Vector.CreateFromArray(diag, false), upper); }