cholsol#
Purpose#
Solves a system of linear equations given the Cholesky factorization of the system.
Format#
- x = cholsol(b, C)#
- Parameters:
b (NxK matrix) – The system is solved for each column in b, i.e., \(A*x[., i] = b[., i]\).
C (NxN matrix) – The Cholesky factorization of a linear system of equations \(A\).
- Returns:
x (NxK matrix) – the solution for \(Ax = b\).
Examples#
/*
** Assign the right-hand side 'b' and the Cholesky
** factorization 'C'
*/
b = { 0.03177513, 0.41823100, 1.70129375 };
C = { 1.73351215 1.53201723 1.78102499,
0 1.09926365 0.63230050,
0 0 0.67015361 };
// Solve the system of equations
x = cholsol(b, C);
// Note: C'C is equivalent to C'*C
A = C'C;
// Solve the system of equations
x2 = b/A;
After the above code, R will equal:
-1.9440 -1.9440
x = -1.5269 x2 = -1.5269
3.2158 3.2158
Remarks#
Since \(A^{-1} = I/A\) and eye(N)
creates an identity matrix of size \(N\):
cholsol(eye(N), C);
is equivalent to:
invpd(A);
Thus, if you have the Cholesky factorization of \(A\), cholsol is the most efficient way to obtain the inverse of \(A\).
See also
Functions chol()