about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/KPMtools/rand_psd.m
diff options
context:
space:
mode:
Diffstat (limited to 'sourcecodes/bnt-master/KPMtools/rand_psd.m')
-rw-r--r--sourcecodes/bnt-master/KPMtools/rand_psd.m13
1 files changed, 13 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/KPMtools/rand_psd.m b/sourcecodes/bnt-master/KPMtools/rand_psd.m
new file mode 100644
index 00000000..c6fc6d32
--- /dev/null
+++ b/sourcecodes/bnt-master/KPMtools/rand_psd.m
@@ -0,0 +1,13 @@
+function M = rand_psd(d, d2, k)
+% Create a random positive definite matrix of size d by d by k (k defaults to 1)
+% M = rand_psd(d, d2, k)   default: d2 = d, k = 1
+
+if nargin<2, d2 = d; end
+if nargin<3, k = 1; end
+if d2 ~= d, error('must be square'); end
+
+M = zeros(d,d,k);
+for i=1:k
+  A = rand(d);
+  M(:,:,i) = A*A';
+end