質問するログイン新規登録

質問編集履歴

1

コードを追加しました。

2021/01/23 02:37

投稿

Okuhira007
Okuhira007

スコア13

title CHANGED
File without changes
body CHANGED
@@ -5,4 +5,60 @@
5
5
 
6
6
  Could not print backtrace: libbacktrace could not find executable to open
7
7
  というエラーが出ています。
8
- モヂュールとメインプログラムで1つのtxtファイル(data14-1)を読み込んだところ、エラーが出ました。
8
+ モヂュールとメインプログラムで1つのtxtファイル(data14-1)を読み込んだところ、エラーが出ました。
9
+ ```fortran
10
+ コードmodule hh
11
+ implicit none
12
+ contains
13
+ function h(kupper, x_c) result(value)
14
+ implicit none
15
+ integer i
16
+ real(8) kupper, x_c, value
17
+ real(8) :: x(0:199)
18
+
19
+ open(11, file='data14-1.txt', status='old')
20
+ value = 0.5*(x_c-2.0)*(x_c-2.0)
21
+ do i = 0, 199
22
+ read(11, *) x(i)
23
+ value = value + 0.5*kupper*(x(i)-x_c)*(x(i)-x_c)
24
+ enddo
25
+ close(11)
26
+ end function h
27
+ end module hh
28
+
29
+ program metropolis2
30
+ use hh
31
+ implicit none
32
+ integer i, j
33
+ real(8) :: epsi1(0:99), epsi2(0:99), x(0:199)
34
+ real(8) :: r(0:99)
35
+ real(8) :: h_prime, x_c = 1.0, kupper = 5.0
36
+
37
+ open(11, file='data14-1.txt', status='old')
38
+ open(12, file='data14-2.txt', status='old')
39
+ open(13, file='data14-3.txt', status='old')
40
+ open(14, file='data14-4.txt', status='old')
41
+ open(15, file='metropolis2.dat', status='replace')
42
+ do i = 0, 99
43
+ read(12,*) epsi1(i)
44
+ read(13,*) epsi2(i)
45
+ read(11,*) x(i)
46
+ x_c = x_c + epsi1(i)
47
+ kupper = kupper + epsi2(i)
48
+ h_prime = h(kupper, x_c)
49
+ read(14,*) r(i)
50
+ if (r(i) <= exp(h(kupper-epsi2(i), x_c-epsi1(i))-h_prime)) then
51
+ continue
52
+ else
53
+ x_c = x_c - epsi1(i)
54
+ kupper = kupper - epsi2(i)
55
+ endif
56
+ write(15, *) i, kupper, x_c
57
+ enddo
58
+ close(11)
59
+ close(12)
60
+ close(13)
61
+ close(14)
62
+ close(15)
63
+ end program metropolis2
64
+ ```