changeset 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 54055b32d516
children f7629720f1b7
files minorsSym.m
diffstat 1 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/minorsSym.m	Wed Feb 03 16:56:05 2016 +0100
@@ -0,0 +1,53 @@
+function ineq = minorsSym(B)
+    B
+
+    [n, m] = size(B);
+
+    if n ~= m
+        error('B must be square');
+    end
+
+    subB = {};
+    ks = {};
+
+    ind = 1:n;
+    for k = 1:n
+        C = nchoosek(ind,k);
+        for i = 1:size(C,1)
+            ks{end + 1} = k;
+            subB{end + 1} = B(C(i,:),C(i,:));
+        end
+    end
+
+
+
+    for i = 1:length(subB)
+        fprintf('%d:\n', ks{i});
+        disp(subB{i})
+
+        minor{i} = det(subB{i});
+    end
+
+    for i = 1:length(subB)
+        fprintf('%d:\n', ks{i});
+        disp(minor{i});
+
+        if mod(ks{i},2) == 0
+            ineq{i} = minor{i} >= 0;
+        else
+            ineq{i} = minor{i} <= 0;
+        end
+    end
+
+    ineqsys = true;
+    for i = 1:length(ineq)
+        ineqsys = ineqsys & ineq{i};
+    end
+
+    ineq = simplify(ineqsys)
+end
+
+
+% B is positive semidefinite if all minors are non-negative
+% B is negative semidefinite if all odd minors are non-positive and all even minors are non-negative
+