1. #include <stdio.h>
2.
3. int main(void){
4.
5. double sigma[2][2] = { {1, 0}, {0, 1} }, W[2] = {1.0, 0.0};
6. //学生番号を入力
7. //double n0 = 2.0, n1 = 1.0, n2 = 0.0, n3 = 1.0;
8. double n0 = 3.0, n1 = 8.0, n2 = 0.0, n3 = 1.0;
9. double x[5][2];
10. double sumx[2] = {0.0};
11. int i;
12.
13. x[0][0] = n1;
14. x[0][1] = n2 + n3;
15. x[1][0] = n0 + n3;
16. x[1][1] = n0 + n1;
17. x[2][0] = n2 + n3;
18. x[2][1] = n1;
19. x[3][0] = n1 + n2;
20. x[3][1] = n1 + n0;
21. x[4][0] = n1 + n0;
22. x[4][1] = n2 + n1 + n0;
23.
24. puts("x");
25. for(i = 0; i < 5; i++)
26. printf("%d %6.4lf %6.4lf\n", i + 1, x[i][0], x[i][1]);
27.
28. for(i = 0; i < 5; i++){
29. sumx[0] += x[i][0];
30. sumx[1] += x[i][1];
31. }
32.
33. printf("\nμ\n%5.3lf %5.3lf\n\n", sumx[0]/5.0, sumx[1]/5.0);
34.
35. puts("x'");
36. for(i = 0; i < 5; i++)
37. printf("%d %6.4lf %6.4lf\n", i + 1, x[i][0] - sumx[0]/5.0, x[i][1] - sumx[1]/5.0);
38.
39. double mu_zx[5] = {0.0}, zz_t[5] = {0.0};
40.
41. printf("\n<z>n\n");
42. for(i = 0; i < 5; i++){
43. mu_zx[i] = (x[i][0] - sumx[0] / 5.0) * 0.5;
44. printf("%d %6.4lf\n", i + 1, mu_zx[i]);
45. }
46.
47. printf("\n<zz>n\n");
48.
49. for(i = 0; i < 5; i++){
50. zz_t[i] = 0.5 + mu_zx[i] * mu_zx[i];
51. printf("%d %6.4lf\n", i + 1, zz_t[i]);
52. }
53.
54. double xx[2][2], zz, xz[2], Sigma[2][2];
55.
56. for(i = 0; i < 5; i++){
57. xx[0][0] += (x[i][0] - sumx[0]/5.0) * (x[i][0] - sumx[0]/5.0);
58. xx[0][1] += (x[i][0] - sumx[0]/5.0) * (x[i][1] - sumx[1]/5.0);
59. xx[1][0] += (x[i][1] - sumx[1]/5.0) * (x[i][0] - sumx[0]/5.0);
60. xx[1][1] += (x[i][1] - sumx[1]/5.0) * (x[i][1] - sumx[1]/5.0);
61. }
62.
63. printf("\nx'x\n%6.4lf %6.4lf\n%6.4lf %6.4lf\n", xx[0][0],xx[0][1],xx[1][0],xx[1][1]);
64.
65. for(i = 0; i < 5; i++){
66. zz += zz_t[i];
67. }
68. printf("\nzz : %6.4lf\n", zz);
69.
70. for(i = 0; i < 5; i++){
71. xz[0] += (x[i][0] - sumx[0] / 5.0) * mu_zx[i];
72. xz[1] += (x[i][1] - sumx[1] / 5.0) * mu_zx[i];
73. }
74.
75. printf("\nx'z : %6.4lf %6.4lf\n", xz[0], xz[1]);
76.
77. printf("\nW = %6.4lf %6.4lf\n", xz[0] * (1.0 / zz), xz[1] * (1.0 / zz) );
78.
79. Sigma[0][0] = (xx[0][0] - xz[0] * xz[0] * (1.0 / zz));
80. Sigma[0][1] = (xx[0][1] - xz[0] * xz[1] * (1.0 / zz));
81. Sigma[1][0] = (xx[1][0] - xz[1] * xz[0] * (1.0 / zz));
82. Sigma[1][1] = (xx[1][1] - xz[1] * xz[1] * (1.0 / zz));
83.
84. //この答えをwolframに突っ込んで対角化行列を求め、5で割るとΣ
85. printf("\nΣ\n%6.4lf %6.4lf\n%6.4lf %6.4lf\n", Sigma[0][0],Sigma[0][1],Sigma[1][0],Sigma[1][1]);
86.
87. double after[2][2];
88.
89. after[0][0] = xz[0] * (1.0 / zz) * xz[0] * (1.0 / zz); //対角成分を加算
90. after[0][1] = xz[0] * (1.0 / zz) * xz[1] * (1.0 / zz);
91. after[1][0] = xz[1] * (1.0 / zz) * xz[0] * (1.0 / zz);
92. after[1][1] = xz[1] * (1.0 / zz) * xz[1] * (1.0 / zz); //対角成分を加算
93.
94. printf("\nAftrer\n%6.4lf %6.4lf\n%6.4lf %6.4lf\n", after[0][0],after[0][1],after[1][0],after[1][1]);
95.
96. return 0;
97.
98. }
99. Wrap • Jul 10th at 11:20 PM • 3kB C snippet • Shared in datamodeling
100. Unshare from #datamodeling
101. fool Jul 10th at 11:20 PM
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘main’:
prog.c:5:44: warning: unused variable ‘W’ [-Wunused-variable]
double sigma[2][2] = { {1, 0}, {0, 1} }, W[2] = {1.0, 0.0};
^
prog.c:5:10: warning: unused variable ‘sigma’ [-Wunused-variable]
double sigma[2][2] = { {1, 0}, {0, 1} }, W[2] = {1.0, 0.0};
^~~~~
prog.c: At top level:
prog.c:99:8: error: stray ‘\342’ in program
Wrap  • Jul 10th at 11:20 PM • 3kB C snippet • Shared in datamodeling
^
prog.c:99:9: error: stray ‘\200’ in program
Wrap  • Jul 10th at 11:20 PM • 3kB C snippet • Shared in datamodeling
^
prog.c:99:10: error: stray ‘\242’ in program
Wrap  • Jul 10th at 11:20 PM • 3kB C snippet • Shared in datamodeling
^
prog.c:99:2: error: unknown type name ‘Wrap’
Wrap  • Jul 10th at 11:20 PM • 3kB C snippet • Shared in datamodeling
^~~~
prog.c:99:16: error: invalid suffix "th" on integer constant
Wrap  • Jul 10th at 11:20 PM • 3kB C snippet • Shared in datamodeling
^~~~
prog.c:99:16: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before numeric constant
prog.c:99:33: error: stray ‘\342’ in program
Wrap  • Jul 10th at 11:20 PM • 3kB C snippet • Shared in datamodeling
^
prog.c:99:34: error: stray ‘\200’ in program
Wrap  • Jul 10th at 11:20 PM • 3kB C snippet • Shared in datamodeling
^
prog.c:99:35: error: stray ‘\242’ in program
Wrap  • Jul 10th at 11:20 PM • 3kB C snippet • Shared in datamodeling
^
prog.c:99:37: error: invalid suffix "kB" on integer constant
Wrap  • Jul 10th at 11:20 PM • 3kB C snippet • Shared in datamodeling
^~~
prog.c:99:51: error: stray ‘\342’ in program
Wrap  • Jul 10th at 11:20 PM • 3kB C snippet • Shared in datamodeling
^
prog.c:99:52: error: stray ‘\200’ in program
Wrap  • Jul 10th at 11:20 PM • 3kB C snippet • Shared in datamodeling
^
prog.c:99:53: error: stray ‘\242’ in program
Wrap  • Jul 10th at 11:20 PM • 3kB C snippet • Shared in datamodeling
^
prog.c:99:77: error: stray ‘\302’ in program
Wrap  • Jul 10th at 11:20 PM • 3kB C snippet • Shared in datamodeling
^
prog.c:99:78: error: stray ‘\240’ in program
Wrap  • Jul 10th at 11:20 PM • 3kB C snippet • Shared in datamodeling
^
prog.c:100:14: error: stray ‘#’ in program
Unshare from #datamodeling
^
prog.c:101:10: error: invalid suffix "th" on integer constant
fool Jul 10th at 11:20 PM
^~~~
stdout
Standard output is empty