comparison m-toolbox/classes/@ao/mchol.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % MCHOL.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: MCHOL
5 %
6 % CALL:
7 %
8 % VERSION: $Id: mchol.m,v 1.3 2008/10/06 12:47:46 ingo Exp $
9 %
10 % HISTORY: ??-??-???? ???
11 % Creation
12 %
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
15 function varargout = mchol(m)
16
17 leng = length(m);
18 for i=1:leng
19 dets(i) = det(m(1:i, 1:i));
20 end
21
22 sqdet = sqrt(dets);
23 if isreal('sqdet')==0
24 error('### matrix not positive definite')
25 end
26
27 if(isa(m,'sym'))
28 M = m;
29 n = length( M );
30 L = vpa(zeros( n, n ));
31 for i=1:n
32 L(i, i) = sqrt( M(i, i) - L(i, :)*L(i, :)' );
33 for j=(i + 1):n
34 L(j, i) = ( M(j, i) - L(i, :)*L(j, :)' )/L(i, i);
35 end
36 end
37 % L = solve('L');
38 varargout{1} = L;
39 end
40
41 end