質問編集履歴
2
コードの訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -17,7 +17,8 @@
|
|
17
17
|
#include <complex.h>
|
18
18
|
#include <stdlib.h>
|
19
19
|
|
20
|
-
#define N
|
20
|
+
#define N 4//次数設定
|
21
|
+
#define L 8
|
21
22
|
#define EPS 0.0001 //収束範囲
|
22
23
|
|
23
24
|
int n = 100000;
|
@@ -25,7 +26,9 @@
|
|
25
26
|
int c = 1;
|
26
27
|
double complex t_1, t_2, t_3, t_4, t_5, t_6; //方向
|
27
28
|
double b_pi;
|
29
|
+
double a[L][L];
|
28
|
-
double
|
30
|
+
double D[2*N];
|
31
|
+
|
29
32
|
|
30
33
|
|
31
34
|
int main(int argc, char** argv) {
|
@@ -45,83 +48,84 @@
|
|
45
48
|
|
46
49
|
int v;
|
47
50
|
for (v = 0;v < n; v++) {
|
48
|
-
k_x = k_x + b_pi * 2
|
49
|
-
t_4 = cos(-1 * a_cube / pow(3, 0.5) * k_y) + I * sin(-1 * a_cube / pow(3, 0.5) * k_y); //cexp(I * (-1* a_cube / pow(3, 0.5) * k_y));
|
50
|
-
t_5 = cos((a_cube / 2 / pow(3, 0.5) * k_x + a_cube / 2 * k_y)) + I * sin((a_cube / 2 / pow(3, 0.5) * k_x + a_cube / 2 * k_y)); //cexp(I * (a_cube / 2 / pow(3, 0.5) * k_x + a_cube / 2 * k_y)); //expの中の符号を計算したあらかじめ
|
51
|
-
t_6 = cos(a_cube / 2 / pow(3, 0.5) * k_x - a_cube / 2 * k_y) + I * sin(a_cube / 2 / pow(3, 0.5) * k_x - a_cube / 2 * k_y); //cexp(I * (a_cube / 2 / pow(3, 0.5) * k_x - a_cube / 2 * k_y)); //
|
52
|
-
t_1 = cos(a_cube / pow(3, 0.5) * k_y) + I * sin(a_cube / pow(3, 0.5) * k_y); //cexp(I * a_cube / pow(3, 0.5) * k_y);
|
53
|
-
t_2 = cos(-a_cube / 2 / pow(3, 0.5) * k_x - a_cube / 2 * k_y) + I * sin(-a_cube / 2 / pow(3, 0.5) * k_x - a_cube / 2 * k_y); //cexp(I * (-a_cube / 2 / pow(3, 0.5) * k_x - a_cube / 2 * k_y));
|
54
|
-
t_3 = cos(-a_cube / 2 / pow(3, 0.5) * k_x + a_cube / 2 * k_y) + I * sin(-a_cube / 2 / pow(3, 0.5) * k_x + a_cube / 2 * k_y); //cexp(I * (-a_cube / 2 / pow(3, 0.5) * k_x + a_cube / 2 * k_y));
|
55
|
-
|
56
|
-
double complex C[N
|
51
|
+
k_x = k_x + b_pi * 2 / a_cube / n;
|
52
|
+
t_4 = cos(-1 * a_cube / pow(3, 0.5) * k_y) + I * sin(-1 * a_cube / pow(3, 0.5) * k_y); //cexp(I * (-1* a_cube / pow(3, 0.5) * k_y));
|
53
|
+
t_5 = cos((a_cube / 2 / pow(3, 0.5) * k_x + a_cube / 2 * k_y)) + I * sin((a_cube / 2 / pow(3, 0.5) * k_x + a_cube / 2 * k_y)); //cexp(I * (a_cube / 2 / pow(3, 0.5) * k_x + a_cube / 2 * k_y)); //expの中の符号を計算したあらかじめ
|
54
|
+
t_6 = cos(a_cube / 2 / pow(3, 0.5) * k_x - a_cube / 2 * k_y) + I * sin(a_cube / 2 / pow(3, 0.5) * k_x - a_cube / 2 * k_y); //cexp(I * (a_cube / 2 / pow(3, 0.5) * k_x - a_cube / 2 * k_y)); //
|
55
|
+
t_1 = cos(a_cube / pow(3, 0.5) * k_y) + I * sin(a_cube / pow(3, 0.5) * k_y); //cexp(I * a_cube / pow(3, 0.5) * k_y);
|
56
|
+
t_2 = cos(-a_cube / 2 / pow(3, 0.5) * k_x - a_cube / 2 * k_y) + I * sin(-a_cube / 2 / pow(3, 0.5) * k_x - a_cube / 2 * k_y); //cexp(I * (-a_cube / 2 / pow(3, 0.5) * k_x - a_cube / 2 * k_y));
|
57
|
+
t_3 = cos(-a_cube / 2 / pow(3, 0.5) * k_x + a_cube / 2 * k_y) + I * sin(-a_cube / 2 / pow(3, 0.5) * k_x + a_cube / 2 * k_y); //cexp(I * (-a_cube / 2 / pow(3, 0.5) * k_x + a_cube / 2 * k_y));
|
58
|
+
|
59
|
+
double complex C[N][N] = {
|
57
60
|
{0,0,t_5 + t_6,0},
|
58
61
|
{0,0,t_4,t_5 + t_6},
|
59
62
|
{t_2 + t_3,t_1, 0, 0},
|
60
63
|
{0,t_2 + t_3, 0, 0} }; //係数行列
|
61
64
|
|
62
|
-
double A[N
|
65
|
+
double A[N][N], B_1[N][N], B_2[N][N];
|
63
|
-
int k, h;
|
66
|
+
int k, h;
|
64
|
-
for (k = 0;k < N
|
67
|
+
for (k = 0;k < N;k++) {
|
65
|
-
for (h = 0;h < N
|
68
|
+
for (h = 0;h < N;h++) {
|
66
|
-
A[k][h] = creal(C[k][h]);
|
69
|
+
A[k][h] = creal(C[k][h]);
|
67
|
-
B_1[k][h] = -1 * cimag(C[k][h]);
|
70
|
+
B_1[k][h] = -1 * cimag(C[k][h]);
|
68
|
-
B_2[k][h] = cimag(C[k][h]);
|
71
|
+
B_2[k][h] = cimag(C[k][h]);
|
69
|
-
}
|
72
|
+
}
|
70
|
-
}
|
73
|
+
}
|
71
|
-
/*for (k = 0;k < N
|
74
|
+
/*for (k = 0;k < N;k++) {
|
72
|
-
for (h = 0;h < N
|
75
|
+
for (h = 0;h < N;h++) {
|
73
|
-
printf("%7.4lf\n",
|
76
|
+
printf("%7.4lf\n", A[k][h]);
|
74
|
-
}
|
77
|
+
}
|
75
|
-
}*/
|
78
|
+
}*/
|
76
|
-
|
77
|
-
|
79
|
+
|
80
|
+
|
78
|
-
/*= {
|
81
|
+
/*= {
|
79
82
|
{A[0][0],A[0][1],A[0][2] ,B_1[0][0],B_1[0][1],B_1[0][2]},
|
80
83
|
{A[1][0],A[1][1],A[1][2] ,B_1[1][0],B_1[1][1],B_1[1][2]},
|
81
84
|
{A[2][0],A[2][1],A[2][2] ,B_1[2][0],B_1[2][1],B_1[2][2]},
|
82
85
|
{B_2[0][0],B_2[0][1],B_2[0][2] ,A[0][0],A[0][1],A[0][2]},
|
83
86
|
{B_2[1][0],B_2[1][1],B_2[1][2] ,A[1][0],A[1][1],A[1][2]},
|
84
87
|
{B_2[2][0],B_2[2][1],B_2[2][2] ,A[2][0],A[2][1],A[2][2]}};*/
|
85
|
-
for (k = 0;k <
|
88
|
+
for (k = 0;k < L;k++) {
|
86
|
-
for (h = 0;h <
|
89
|
+
for (h = 0;h < L;h++) {
|
87
|
-
if (h < N
|
90
|
+
if (h < N){
|
88
|
-
if (k < N
|
91
|
+
if (k < N)
|
89
|
-
a[h][k] = A[h % N
|
92
|
+
a[h][k] = A[h % N][k % N];
|
90
|
-
else
|
93
|
+
else
|
91
|
-
a[h][k] = B_1[h % N
|
94
|
+
a[h][k] = B_1[h % N][k % N];
|
92
|
-
}
|
95
|
+
}
|
93
|
-
else {
|
96
|
+
else {
|
94
|
-
if (k < N
|
97
|
+
if (k < N)
|
95
|
-
a[h][k] = B_2[h % N
|
98
|
+
a[h][k] = B_2[h % N][k % N];
|
96
|
-
else
|
99
|
+
else
|
97
|
-
a[h][k] = A[h % N
|
100
|
+
a[h][k] = A[h % N][k % N];
|
98
|
-
}
|
101
|
+
}
|
99
|
-
}
|
102
|
+
}
|
100
|
-
}
|
103
|
+
}
|
104
|
+
|
101
|
-
/*/for (k = 0;k <
|
105
|
+
/*/for (k = 0;k < L;k++) {
|
102
|
-
for (h = 0;h <
|
106
|
+
for (h = 0;h < L;h++)
|
103
|
-
printf("%7.4lf\n", a[k][h]);
|
107
|
+
printf("%7.4lf\n", a[k][h]);
|
104
|
-
}*/
|
108
|
+
}*/
|
105
|
-
|
109
|
+
|
106
|
-
//double u[
|
110
|
+
//double u[L][L]; //単位行列
|
107
|
-
double alpha, beta, gamma;
|
111
|
+
double alpha, beta, gamma;
|
108
|
-
double s, c, w;
|
112
|
+
double s, c, w;
|
109
|
-
double wa, wb, wc;
|
113
|
+
double wa, wb, wc;
|
110
|
-
double max;
|
114
|
+
double max;
|
111
|
-
int i, j, p, q, x, y;
|
115
|
+
int i, j, p, q, x, y;
|
112
|
-
|
116
|
+
|
113
|
-
/*for (y = 0;y < N;y++)
|
117
|
+
/*for (y = 0;y < N;y++)
|
114
118
|
for (x = 0;x < N;x++)
|
115
119
|
u[y][x] = 0.0;
|
116
120
|
|
117
121
|
for (i = 0;i < N;i++)
|
118
122
|
u[i][i] = 1.0;*/
|
119
123
|
|
120
|
-
while (1) {
|
124
|
+
while (1) {
|
121
125
|
//最大要素の行と列を検索
|
122
126
|
max = 0.0;
|
123
|
-
for (i = 0;i <
|
127
|
+
for (i = 0;i < L - 1;i++) {
|
124
|
-
for (j = i + 1;j <
|
128
|
+
for (j = i + 1;j < L;j++)
|
125
129
|
if (fabs(a[i][j]) > max) {
|
126
130
|
p = i;
|
127
131
|
q = j;
|
@@ -142,13 +146,13 @@
|
|
142
146
|
if (alpha * beta < 0) s = -s;
|
143
147
|
c = sqrt(1.0 - s * s);
|
144
148
|
//直行変換
|
145
|
-
for (j = 0;j <
|
149
|
+
for (j = 0;j < L;j++) {
|
146
150
|
w = a[p][j] * c - a[q][j] * s;
|
147
151
|
a[q][j] = a[p][j] * s + a[q][j] * c;
|
148
152
|
a[p][j] = w;
|
149
153
|
}
|
150
154
|
|
151
|
-
for (j = 0;j <
|
155
|
+
for (j = 0;j < L;j++) {
|
152
156
|
a[j][p] = a[p][j];
|
153
157
|
a[j][q] = a[q][j];
|
154
158
|
|
@@ -168,35 +172,35 @@
|
|
168
172
|
u[i][p] = w;
|
169
173
|
}*/
|
170
174
|
|
171
|
-
for (i = 0;i < N;i++) {
|
172
|
-
|
175
|
+
D[0] = a[0][0];
|
173
|
-
|
176
|
+
D[1] = a[1][1];
|
177
|
+
D[2] = a[2][2];
|
178
|
+
D[3] = a[3][3];
|
179
|
+
D[4] = a[4][4];
|
180
|
+
D[5] = a[5][5];
|
181
|
+
D[6] = a[6][6];
|
182
|
+
D[7] = a[7][7];
|
183
|
+
|
184
|
+
|
174
|
-
for (k = 0;k <
|
185
|
+
/*for (k = 0;k < L;k++) {
|
175
|
-
for (h = 0;h <
|
186
|
+
for (h = 0;h < L; h++) {
|
176
187
|
printf("%7.4lf\n", a[k]);
|
177
188
|
}
|
178
|
-
}
|
189
|
+
}*/
|
179
|
-
|
180
190
|
}
|
191
|
+
|
181
|
-
fprintf(fp, "%2f %lf %lf %lf %lf %lf %lf %lf %lf\n", k_x, D[0], D[1], D[2], D[3], D[4], D[5], D[6], D[7]);
|
192
|
+
fprintf(fp, "%2f %lf %lf %lf %lf %lf %lf %lf %lf\n", k_x, D[0], D[1], D[2], D[3], D[4], D[5], D[6], D[7]);
|
182
193
|
}
|
183
194
|
|
195
|
+
/*int i;
|
184
|
-
|
196
|
+
printf("固有値\n");
|
185
|
-
for (i = 0;i <
|
197
|
+
for (i = 0;i < L;i++) {
|
186
198
|
printf("%7.4lf\n", a[i][i]); //対角成分 こいつが固有値
|
187
|
-
printf("\n\n");*/
|
188
|
-
/*printf("固有ベクトル\n");
|
189
|
-
for (i = 0;i<N;i++) {
|
190
|
-
for(j=0;j<N;j++)
|
191
|
-
printf( "%7.4lf", u[i][j]); //固有ベクトル
|
192
|
-
printf("\n");
|
193
|
-
*/
|
199
|
+
}*/
|
200
|
+
|
194
201
|
fclose(fp);
|
195
202
|
return 0;
|
196
203
|
}
|
197
|
-
|
198
|
-
|
199
|
-
|
200
204
|
```
|
201
205
|
|
202
206
|
### 試したこと
|
1
問題点とやりたいこと加筆
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,8 +6,7 @@
|
|
6
6
|
「あるk_xに対してこの値」みたいなプログラミングにしたい
|
7
7
|
### 発生している問題・エラーメッセージ
|
8
8
|
同じ値しか出てこない
|
9
|
-
|
9
|
+
あるk_xに対して行列a[][]が決まって、そのa[][]の固有値を計算してその値をD[]に入れるようなプログラミングが書きたいのですが、ほしい値が出てきていないのが現状です
|
10
|
-
|
11
10
|
### 該当のソースコード
|
12
11
|
|
13
12
|
```C
|