回答編集履歴

2

微修正

2020/07/03 12:22

投稿

episteme
episteme

スコア16612

test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
 
13
- #define at(t,x,y) t[y*4+x]
13
+ #define at(t,y,x) t[y*4+x]
14
14
 
15
15
 
16
16
 

1

追記

2020/07/03 12:22

投稿

episteme
episteme

スコア16612

test CHANGED
@@ -1 +1,89 @@
1
1
  簡単もなにもベクトルの内積を4x4回繰り返す以外なんかあるん?
2
+
3
+
4
+
5
+ [追記] 愚直な実装でよければ:
6
+
7
+ ```C
8
+
9
+ #include <stdio.h>
10
+
11
+
12
+
13
+ #define at(t,x,y) t[y*4+x]
14
+
15
+
16
+
17
+ int main() {
18
+
19
+ float a[16] = {
20
+
21
+ 1.000000,0.000000,0.000000,0.000000,
22
+
23
+ 0.000000,1.000000,0.000000,0.000000,
24
+
25
+ 0.000000,0.000000,1.000000,0.000000,
26
+
27
+ 0.000000,0.000000,0.000000,1.000000 };
28
+
29
+
30
+
31
+ float b[16] = {
32
+
33
+ 1.000000,0.000000,0.000000,0.000000,
34
+
35
+ 0.000000,1.000000,0.000000,0.000000,
36
+
37
+ 0.000000,0.000000,1.000000,0.000000,
38
+
39
+ 0.000000,0.000000,0.000000,1.000000 };
40
+
41
+
42
+
43
+ float c[16];
44
+
45
+
46
+
47
+ int row, col;
48
+
49
+ for ( row = 0; row < 4; ++row ) {
50
+
51
+ for ( col =0; col < 4; ++col ) {
52
+
53
+ float sum = 0.0f;
54
+
55
+ int t;
56
+
57
+ for ( t = 0; t <4; ++t ) {
58
+
59
+ sum += at(a,row,t) * at(b,t,col);
60
+
61
+ }
62
+
63
+ at(c,row,col) = sum;
64
+
65
+ }
66
+
67
+ }
68
+
69
+
70
+
71
+ // できたかな?
72
+
73
+ for ( row = 0; row < 4; ++row) {
74
+
75
+ for ( col = 0; col < 4; ++col) {
76
+
77
+ printf("%f ", at(c,row,col));
78
+
79
+ }
80
+
81
+ puts("");
82
+
83
+ }
84
+
85
+ return 0;
86
+
87
+ }
88
+
89
+ ```