comparison minorsSym.m @ 127:967152d7d58b

Added function for printing the minors of a matrix.
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 03 Feb 2016 16:56:05 +0100
parents
children
comparison
equal deleted inserted replaced
126:54055b32d516 127:967152d7d58b
1 function ineq = minorsSym(B)
2 B
3
4 [n, m] = size(B);
5
6 if n ~= m
7 error('B must be square');
8 end
9
10 subB = {};
11 ks = {};
12
13 ind = 1:n;
14 for k = 1:n
15 C = nchoosek(ind,k);
16 for i = 1:size(C,1)
17 ks{end + 1} = k;
18 subB{end + 1} = B(C(i,:),C(i,:));
19 end
20 end
21
22
23
24 for i = 1:length(subB)
25 fprintf('%d:\n', ks{i});
26 disp(subB{i})
27
28 minor{i} = det(subB{i});
29 end
30
31 for i = 1:length(subB)
32 fprintf('%d:\n', ks{i});
33 disp(minor{i});
34
35 if mod(ks{i},2) == 0
36 ineq{i} = minor{i} >= 0;
37 else
38 ineq{i} = minor{i} <= 0;
39 end
40 end
41
42 ineqsys = true;
43 for i = 1:length(ineq)
44 ineqsys = ineqsys & ineq{i};
45 end
46
47 ineq = simplify(ineqsys)
48 end
49
50
51 % B is positive semidefinite if all minors are non-negative
52 % B is negative semidefinite if all odd minors are non-positive and all even minors are non-negative
53