質問編集履歴
3
誤字
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
磁力の関係についてのシュミレーションができません。
|
1
|
+
磁力の関係についてのシュミレーションができません。(訂正版)
|
test
CHANGED
File without changes
|
2
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,12 +6,13 @@
|
|
6
6
|
```> ### C
|
7
7
|
#include<stdio.h>
|
8
8
|
#include<stdlib.h>
|
9
|
+
#include<math.h>
|
9
|
-
#define N(20)
|
10
|
+
#define N (20)
|
10
11
|
|
11
12
|
int main(){
|
12
13
|
double J = 2.0e-21;
|
13
|
-
double E;
|
14
|
+
double E1,E2,T,P,kbT,N;
|
14
|
-
int i,j,n,
|
15
|
+
int i,j,n,p;
|
15
16
|
int m[N][N];
|
16
17
|
|
17
18
|
//磁化を代入する
|
@@ -23,20 +24,35 @@
|
|
23
24
|
m[i][j]=(rand()%2)*2-1;
|
24
25
|
|
25
26
|
//ランダム磁化②
|
26
|
-
if((double)rand() RAND_MAX > 0.5)m[i][j]
|
27
|
+
if((double)rand() / RAND_MAX > 0.5)m[i][j] = 1;
|
27
28
|
else m[i][j]=-1;
|
28
29
|
}
|
29
30
|
}
|
30
31
|
//エネルギー計算
|
31
|
-
E=0.0;
|
32
|
+
E1=0.0;
|
32
33
|
for(j=0;j<N;j++){
|
33
34
|
for(i=0;i<N;i++){
|
34
|
-
if(i < N-1)E += -J*m[i][j]*m[i+1][j];
|
35
|
+
if(i < N-1)E1 += -J*m[i][j]*m[i+1][j];
|
35
|
-
if(j < N-1)E += -J*m[i][j]*m[i][j+1];
|
36
|
+
if(j < N-1)E1 += -J*m[i][j]*m[i][j+1];
|
36
37
|
}
|
37
38
|
}
|
39
|
+
//ランダムで磁化を変化させるサイトを決定
|
40
|
+
i = rand()%20;
|
41
|
+
j = rand()%20;
|
42
|
+
m[i][j] = -m[i][j];
|
43
|
+
//エネルギー計算
|
44
|
+
E2=0.0;
|
45
|
+
for(j=0;j<N;j++){
|
46
|
+
for(i=0;i<N;i++){
|
47
|
+
if(i < N-1)E2 += -J*m[i][j]*m[i+1][j];
|
48
|
+
if(j < N-1)E2 += -J*m[i][j]*m[i][j+1];
|
49
|
+
}
|
50
|
+
}
|
51
|
+
for(T=10;T<500;T=T+10){
|
52
|
+
kbT = kbT * (double)T;
|
53
|
+
p = 1.0/(1.0+exp(-(E1-E2)/(kbT) ));
|
38
|
-
printf("%e \n",E);
|
54
|
+
printf("% lf %e %e %e\n",(double)T,P,E1,E2);
|
39
|
-
|
55
|
+
}
|
40
56
|
}
|
41
57
|
```
|
42
58
|
### 実現したいこと
|
@@ -46,39 +62,13 @@
|
|
46
62
|
|
47
63
|
```
|
48
64
|
エラーメッセージ
|
49
|
-
2.c:3:11: error: "20" may not appear in macro parameter list
|
50
|
-
#define N(20)
|
51
|
-
^~
|
52
65
|
2.c: In function 'main':
|
66
|
+
2.c:4:12: error: expected identifier or '(' before numeric constant
|
67
|
+
#define N (20)
|
68
|
+
^~
|
53
|
-
2.c:8:
|
69
|
+
2.c:8:23: note: in expansion of macro 'N'
|
54
|
-
|
70
|
+
double E1,E2,T,P,kbT,N;
|
55
|
-
^
|
71
|
+
^
|
56
|
-
2.c:7:17: note: previous declaration of 'P' was here
|
57
|
-
double E1,E2,T,P,kb;
|
58
|
-
^
|
59
|
-
2.c:20:21: error: expected ')' before numeric constant
|
60
|
-
if((double)rand() RAND_MAX > 0.5)m[i][j]-1;
|
61
|
-
~ ^
|
62
|
-
)
|
63
|
-
2.c:45:3: error: 'kbT' undeclared (first use in this function); did you mean 'kb'?
|
64
|
-
kbT = kb * (double)T;
|
65
|
-
^~~
|
66
|
-
kb
|
67
|
-
2.c:45:3: note: each undeclared identifier is reported only once for each function it appears in
|
68
|
-
2.c:46:3: error: 'p' undeclared (first use in this function)
|
69
|
-
p = 1.0/(1.0+exp(-(E1-E2)/(kbT) ));
|
70
|
-
^
|
71
|
-
2.c:46:16: warning: implicit declaration of function 'exp' [-Wimplicit-function-declaration]
|
72
|
-
p = 1.0/(1.0+exp(-(E1-E2)/(kbT) ));
|
73
|
-
^~~
|
74
|
-
2.c:46:16: warning: incompatible implicit declaration of built-in function 'exp'
|
75
|
-
2.c:46:16: note: include '<math.h>' or provide a declaration of 'exp'
|
76
|
-
2.c:3:1:
|
77
|
-
+#include <math.h>
|
78
|
-
#define N(20)
|
79
|
-
2.c:46:16:
|
80
|
-
p = 1.0/(1.0+exp(-(E1-E2)/(kbT) ));
|
81
|
-
^~~
|
82
72
|
```
|
83
73
|
|
84
74
|
|
1
文法
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,55 +2,8 @@
|
|
2
2
|
下のプログラムを立ててこれを利用してシュミレーションをしてみたいのですが、エラーの内容や改善方法がよくわかりません。
|
3
3
|
助けて欲しいです。
|
4
4
|
何卒宜しくお願い致します。
|
5
|
-
```> ### ここに言語を入力
|
6
|
-
コード
|
7
|
-
```
|
8
|
-
### 実現したいこと
|
9
|
-
計算値を用いたgnuplotでグラフを作成したいです。
|
10
|
-
###
|
11
5
|
|
12
|
-
|
13
|
-
```
|
14
|
-
エラーメッセージ
|
15
|
-
```
|
16
|
-
2.c:3:11: error: "20" may not appear in macro parameter list
|
17
|
-
#
|
6
|
+
```> ### C
|
18
|
-
^~
|
19
|
-
2.c: In function 'main':
|
20
|
-
2.c:8:14: error: conflicting types for 'P'
|
21
|
-
int i,j,n,N,P;
|
22
|
-
^
|
23
|
-
2.c:7:17: note: previous declaration of 'P' was here
|
24
|
-
double E1,E2,T,P,kb;
|
25
|
-
^
|
26
|
-
2.c:20:21: error: expected ')' before numeric constant
|
27
|
-
if((double)rand() RAND_MAX > 0.5)m[i][j]-1;
|
28
|
-
~ ^
|
29
|
-
)
|
30
|
-
2.c:45:3: error: 'kbT' undeclared (first use in this function); did you mean 'kb'?
|
31
|
-
kbT = kb * (double)T;
|
32
|
-
^~~
|
33
|
-
kb
|
34
|
-
2.c:45:3: note: each undeclared identifier is reported only once for each function it appears in
|
35
|
-
2.c:46:3: error: 'p' undeclared (first use in this function)
|
36
|
-
p = 1.0/(1.0+exp(-(E1-E2)/(kbT) ));
|
37
|
-
^
|
38
|
-
2.c:46:16: warning: implicit declaration of function 'exp' [-Wimplicit-function-declaration]
|
39
|
-
p = 1.0/(1.0+exp(-(E1-E2)/(kbT) ));
|
40
|
-
^~~
|
41
|
-
2.c:46:16: warning: incompatible implicit declaration of built-in function 'exp'
|
42
|
-
2.c:46:16: note: include '<math.h>' or provide a declaration of 'exp'
|
43
|
-
2.c:3:1:
|
44
|
-
+#include <math.h>
|
45
|
-
#define N(20)
|
46
|
-
2.c:46:16:
|
47
|
-
p = 1.0/(1.0+exp(-(E1-E2)/(kbT) ));
|
48
|
-
^~~
|
49
|
-
### 該当のソースコード
|
50
|
-
|
51
|
-
```C
|
52
|
-
|
53
|
-
```
|
54
7
|
#include<stdio.h>
|
55
8
|
#include<stdlib.h>
|
56
9
|
#define N(20)
|
@@ -85,6 +38,49 @@
|
|
85
38
|
printf("%e \n",E);
|
86
39
|
//E=-1.52e-18となる。
|
87
40
|
}
|
41
|
+
```
|
42
|
+
### 実現したいこと
|
43
|
+
計算値を用いたgnuplotでグラフを作成したいです。
|
44
|
+
###
|
45
|
+
|
46
|
+
|
47
|
+
```
|
48
|
+
エラーメッセージ
|
49
|
+
2.c:3:11: error: "20" may not appear in macro parameter list
|
50
|
+
#define N(20)
|
51
|
+
^~
|
52
|
+
2.c: In function 'main':
|
53
|
+
2.c:8:14: error: conflicting types for 'P'
|
54
|
+
int i,j,n,N,P;
|
55
|
+
^
|
56
|
+
2.c:7:17: note: previous declaration of 'P' was here
|
57
|
+
double E1,E2,T,P,kb;
|
58
|
+
^
|
59
|
+
2.c:20:21: error: expected ')' before numeric constant
|
60
|
+
if((double)rand() RAND_MAX > 0.5)m[i][j]-1;
|
61
|
+
~ ^
|
62
|
+
)
|
63
|
+
2.c:45:3: error: 'kbT' undeclared (first use in this function); did you mean 'kb'?
|
64
|
+
kbT = kb * (double)T;
|
65
|
+
^~~
|
66
|
+
kb
|
67
|
+
2.c:45:3: note: each undeclared identifier is reported only once for each function it appears in
|
68
|
+
2.c:46:3: error: 'p' undeclared (first use in this function)
|
69
|
+
p = 1.0/(1.0+exp(-(E1-E2)/(kbT) ));
|
70
|
+
^
|
71
|
+
2.c:46:16: warning: implicit declaration of function 'exp' [-Wimplicit-function-declaration]
|
72
|
+
p = 1.0/(1.0+exp(-(E1-E2)/(kbT) ));
|
73
|
+
^~~
|
74
|
+
2.c:46:16: warning: incompatible implicit declaration of built-in function 'exp'
|
75
|
+
2.c:46:16: note: include '<math.h>' or provide a declaration of 'exp'
|
76
|
+
2.c:3:1:
|
77
|
+
+#include <math.h>
|
78
|
+
#define N(20)
|
79
|
+
2.c:46:16:
|
80
|
+
p = 1.0/(1.0+exp(-(E1-E2)/(kbT) ));
|
81
|
+
^~~
|
82
|
+
```
|
83
|
+
|
88
84
|
|
89
85
|
### 試したこと
|
90
86
|
1.温度300K, 500Kにおけるステップ数(横軸)と磁化(縦軸)のグラフを作成しなさい。
|