comparison minors.m @ 129:0a881a3dc9a9

Cleaned up the code for minors.
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 03 Feb 2016 17:41:46 +0100
parents minorsSym.m@967152d7d58b
children eaf557023fbe
comparison
equal deleted inserted replaced
128:f7629720f1b7 129:0a881a3dc9a9
1 function [minor, sub] = minors(A)
2 [n, m] = size(A);
3
4 if n ~= m
5 error('A must be square');
6 end
7
8 sub = {};
9 ks = {};
10
11 ind = 1:n;
12 for k = 1:n
13 C = nchoosek(ind,k);
14 for i = 1:size(C,1)
15 ks{end + 1} = k;
16 sub{end + 1} = A(C(i,:),C(i,:));
17 end
18 end
19
20 for i = 1:length(sub)
21 fprintf('%d:\n', ks{i});
22 disp(sub{i})
23
24 minor(i) = det(sub{i});
25 end
26 end
27
28
29 % A is positive semidefinite if all minors are non-negative
30 % A is negative semidefinite if all odd minors are non-positive and all even minors are non-negative
31