diff options
author | Piotr Dziwinski <piotrdz@gmail.com> | 2012-04-29 23:21:35 +0200 |
---|---|---|
committer | Piotr Dziwinski <piotrdz@gmail.com> | 2012-04-29 23:21:35 +0200 |
commit | 7369b10a87aed982de328fbfa242666928e021d6 (patch) | |
tree | a49761c68be613f9baf4a50dc864d1a1d3bb86c1 /src/math/test/gendata.m | |
parent | b5b9fdb6803f5c5c70a39bd1abe65c6b651886a9 (diff) | |
download | colobot-7369b10a87aed982de328fbfa242666928e021d6.tar.gz colobot-7369b10a87aed982de328fbfa242666928e021d6.tar.bz2 colobot-7369b10a87aed982de328fbfa242666928e021d6.zip |
Structs continued
Diffstat (limited to 'src/math/test/gendata.m')
-rw-r--r-- | src/math/test/gendata.m | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/math/test/gendata.m b/src/math/test/gendata.m new file mode 100644 index 0000000..5c13491 --- /dev/null +++ b/src/math/test/gendata.m @@ -0,0 +1,86 @@ +% Script in Octave for generating test data + +1; + +% Returns the minor matrix +function m = minor(A, r, c) + + m = A; + m(r,:) = []; + m(:,c) = []; + +end; + +% Returns the cofactor matrix +function m = cofactors(A) + + m = zeros(rows(A), columns(A)); + + for r = [1 : rows(A)] + for c = [1 : columns(A)] + m(r, c) = det(minor(A, r, c)); + if (mod(r + c, 2) == 1) + m(r, c) = -m(r, c); + end; + end; + end; + +end; + +% Prints the matrix as C++ code +function printout(A, name) + + printf('const float %s[16] = \n', name); + printf('{\n'); + + for c = [1 : columns(A)] + for r = [1 : rows(A)] + printf(' %f', A(r,c)); + if (! ( (r == 4) && (c == 4) ) ) + printf(','); + end; + printf('\n'); + end; + end; + + printf('};\n'); + +end; + +printf('// Cofactors\n'); +A = randn(4,4); +printout(A, 'COF_MAT'); +printf('\n'); +printout(cofactors(A), 'COF_RESULT'); +printf('\n'); + +printf('\n'); + +printf('// Det\n'); +A = randn(4,4); +printout(A, 'DET_MAT'); +printf('\n'); +printf('const float DET_RESULT = %f;', det(A)); +printf('\n'); + +printf('\n'); + +printf('// Invert\n'); +A = randn(4,4); +printout(A, 'INV_MAT'); +printf('\n'); +printout(inv(A), 'COF_RESULT'); +printf('\n'); + +printf('\n'); + +printf('// Multiplication\n'); +A = randn(4,4); +printout(A, 'MUL_A'); +printf('\n'); +B = randn(4,4); +printout(B, 'MUL_B'); +printf('\n'); +C = A * B; +printout(C, 'MUL_RESULT'); +printf('\n'); |