-
Notifications
You must be signed in to change notification settings - Fork 0
/
solve_chol.m
25 lines (21 loc) · 994 Bytes
/
solve_chol.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
% solve_chol - solve linear equations from the Cholesky factorization.
% Solve A*X = B for X, where A is square, symmetric, positive definite. The
% input to the function is R the Cholesky decomposition of A and the matrix B.
% Example: X = solve_chol(chol(A),B);
%
% NOTE: The program code is written in the C language for efficiency and is
% contained in the file solve_chol.c, and should be compiled using matlabs mex
% facility. However, this file also contains a (less efficient) matlab
% implementation, supplied only as a help to people unfamiliar with mex. If
% the C code has been properly compiled and is available, it automatically
% takes precendence over the matlab code in this file.
%
% Copyright (c) by Carl Edward Rasmussen and Hannes Nickisch 2010-09-18.
function X = solve_chol(L, B)
if nargin ~= 2 || nargout > 1
error('Wrong number of arguments.');
end
if size(L,1) ~= size(L,2) || size(L,1) ~= size(B,1)
error('Wrong sizes of matrix arguments.');
end
X = L\(L'\B);