about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/KPMtools/is_psd.m
diff options
context:
space:
mode:
Diffstat (limited to 'sourcecodes/bnt-master/KPMtools/is_psd.m')
-rw-r--r--sourcecodes/bnt-master/KPMtools/is_psd.m11
1 files changed, 11 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/KPMtools/is_psd.m b/sourcecodes/bnt-master/KPMtools/is_psd.m
new file mode 100644
index 00000000..ff3baa54
--- /dev/null
+++ b/sourcecodes/bnt-master/KPMtools/is_psd.m
@@ -0,0 +1,11 @@
+function b = positive_semidefinite(M)
+%
+% Return true iff v M v' >= 0 for any vector v.
+% We do this by checking that all the eigenvalues are non-negative.
+
+E = eig(M);
+if length(find(E>=0)) == length(E)
+  b = 1;
+else
+  b = 0;
+end