1 function R = cholesky_inf(A, tolerance)
3 % Peform the Cholesky-Infinity factorization of ``A``. This differs
4 % from the ordinary Cholesky factorization in that it handles
5 % matrices which are not positive-definite.
7 % If a non-positive diagonal entry appears, it is replaced with
8 % ``inf`` and the rest of that row is set to zero. This will force a
9 % zero in the corresponding row of the solution vector.
11 % This function is based on the description of MATLAB's `cholinc(A,
12 % 'inf')` function which has been deprecated and removed.
16 % - ``A`` -- The matrix to factor.
18 % - ``tolerance`` -- (default: eps) The zero tolerance used to test
19 % the diagonal entries. If `A(i,i) <= tolerance`,
20 % then we consider `A(i,i) to be zero.
24 % - ``R`` -- The upper-triangular Cholesky factor of ``A``. ``R``
25 % will be sparse if ``A`` is.
34 % If `A` is sparse, `R` should be too.
41 col_above = R(1:i-1, i);
42 R(i,i) = A(i,i) - col_above'*col_above;
44 if (R(i,i) <= tolerance)
45 % A is not positive-definite. Rather than throw an error here,
46 % we set this pivot to 'inf' and the rest of the row to zero.
50 % Normal case with the pivot greater than zero.
51 R(i,i) = sqrt(R(i,i));
56 R(i,j) = (A(i,j) - row1'*row2)/R(i,i);