aboutsummaryrefslogtreecommitdiffstats
path: root/buch/chapters/50-permutationen/beispiele
diff options
context:
space:
mode:
authorLordMcFungus <mceagle117@gmail.com>2021-03-22 18:05:11 +0100
committerGitHub <noreply@github.com>2021-03-22 18:05:11 +0100
commit76d2d77ddb2bed6b7c6b8ec56648d85da4103ab7 (patch)
tree11b2d41955ee4bfa0ae5873307c143f6b4d55d26 /buch/chapters/50-permutationen/beispiele
parentmore chapter structure (diff)
parentadd title image (diff)
downloadSeminarMatrizen-76d2d77ddb2bed6b7c6b8ec56648d85da4103ab7.tar.gz
SeminarMatrizen-76d2d77ddb2bed6b7c6b8ec56648d85da4103ab7.zip
Merge pull request #1 from AndreasFMueller/master
update
Diffstat (limited to 'buch/chapters/50-permutationen/beispiele')
-rw-r--r--buch/chapters/50-permutationen/beispiele/perm.m44
1 files changed, 44 insertions, 0 deletions
diff --git a/buch/chapters/50-permutationen/beispiele/perm.m b/buch/chapters/50-permutationen/beispiele/perm.m
new file mode 100644
index 0000000..2e837ef
--- /dev/null
+++ b/buch/chapters/50-permutationen/beispiele/perm.m
@@ -0,0 +1,44 @@
+#
+# perm.m -- find a random permutation
+#
+# (c) 2021 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
+#
+N = 8
+M = N+1
+
+function retval = permutation(n)
+ p = (1:n);
+ for i = (1:(n-1))
+ j = i + 1 + floor(rand() * (n-i));
+ s = p(i);
+ p(i) = p(j);
+ p(j) = s;
+ endfor
+ retval = p;
+end
+
+function retval = compose(p,q)
+ n = size(p)(1,2);
+ retval = zeros(1,n);
+ for i = (1:n)
+ retval(i) = q(p(i));
+ end
+end
+
+sigma = permutation(N)
+sigma = compose(sigma, permutation(N))
+sigma = compose(sigma, permutation(N))
+sigma = compose(sigma, permutation(N))
+sigma = compose(sigma, permutation(N))
+sigma = compose(sigma, permutation(N))
+sigma = compose(sigma, permutation(N))
+
+s = zeros(M,N);
+s(1,:) = sigma;
+for i = (2:M)
+ s(i,:) = compose(s(i-1,:), sigma);
+end
+
+s
+
+compose(sigma, permutation(N))