diff options
author | Andreas Müller <andreas.mueller@othello.ch> | 2021-01-19 22:08:40 +0100 |
---|---|---|
committer | Andreas Müller <andreas.mueller@othello.ch> | 2021-01-19 22:08:40 +0100 |
commit | 45794fb198c8fac02b5c82b6ac3f1e17bac1075e (patch) | |
tree | 038f99ee46536f8f46e48358454c5868c429af09 /buch/chapters/50-permutationen/beispiele/perm.m | |
parent | repurposing spectral radius section (diff) | |
download | SeminarMatrizen-45794fb198c8fac02b5c82b6ac3f1e17bac1075e.tar.gz SeminarMatrizen-45794fb198c8fac02b5c82b6ac3f1e17bac1075e.zip |
Permutationen hinzugefügt
Diffstat (limited to '')
-rw-r--r-- | buch/chapters/50-permutationen/beispiele/perm.m | 44 |
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)) |