forked from lawrennd/ndlutil
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpdinv.m
56 lines (50 loc) · 1.55 KB
/
pdinv.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function [Ainv, UC, jitter] = pdinv(A, UC)
% PDINV Invert a positive definite matrix.
% FORMAT
% DESC inverts a positive definite matrix. If the matrix isn't
% quite positive definite the function adds 'jitter' to make it
% positive definite and gives out a warning message (this is done
% through JITCHOL).
% ARG A : the input positive definite matrix to be inverted.
% RETURN Ainv : the inverse of A computed using Cholesky
% decomposition.
% RETURN U : the Cholesky decomposition of A.
%
% FORMAT
% DESC inverts a positive definite matrix given the Cholesky
% decomposition of A.
% ARG A : the input positive definite matrix to be inverted.
% ARG U : the Cholesky decomposition of A.
% RETURN Ainv : the inverse of A computed using Cholesky
% decomposition.
% RETURN U : the Cholesky decomposition of A.
%
% FORMAT
% DESC inverts a positive definite matrix given the Cholesky
% decomposition of A. If jitter is used then the
% amount of jitter used is returned.
% ARG A : the input positive definite matrix to be inverted.
% ARG U : the Cholesky decomposition of A.
% RETURN Ainv : the inverse of A computed using Cholesky
% decomposition.
% RETURN U : the Cholesky decomposition of A.
% RETURN jitter : the amount of jitter added.
%
% SEEALSO : jitChol, logdet, chol
%
% COPYRIGHT : Neil D. Lawrence, 2003, 2004, 2005, 2006
% NDLUTIL
if nargin < 2
UC=[];
end
% Obtain a Cholesky decomposition.
if isempty(UC)
if nargout > 2
[UC, jitter] = jitChol(A);
else
UC = jitChol(A);
end
end
invU = UC\eye(size(A, 1));
%invU = eye(size(A, 1))/UC;
Ainv = invU*invU';