質問編集履歴
1
データpi_valueの生成部分のコードも掲載しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -36,7 +36,39 @@
|
|
36
36
|
|
37
37
|
|
38
38
|
|
39
|
+
|
40
|
+
|
39
41
|
```python
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
r = 0.5
|
46
|
+
|
47
|
+
point_in = 0
|
48
|
+
|
49
|
+
pi_value = []
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
for i in range(100000):
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
x = np.random.rand()
|
58
|
+
|
59
|
+
y = np.random.rand()
|
60
|
+
|
61
|
+
distance = np.sqrt((x - 0.5)**2 + (y - 0.5)**2)
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
if distance <= r:
|
66
|
+
|
67
|
+
point_in += 1
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
pi_value.append(4 * (point_in / 100000))
|
40
72
|
|
41
73
|
plt.plot(pi_value)
|
42
74
|
|