回答編集履歴
1
d
test
CHANGED
@@ -1,8 +1,4 @@
|
|
1
1
|
以下の手順で求めればよいと思います。
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
2
|
|
7
3
|
|
8
4
|
|
@@ -21,6 +17,8 @@
|
|
21
17
|
|
22
18
|
|
23
19
|
```python
|
20
|
+
|
21
|
+
import matplotlib.pyplot as plt
|
24
22
|
|
25
23
|
import numpy as np
|
26
24
|
|
@@ -44,57 +42,9 @@
|
|
44
42
|
|
45
43
|
infections = xs[indices]
|
46
44
|
|
47
|
-
```
|
48
45
|
|
49
46
|
|
50
|
-
|
51
|
-
上記のコメント付きのコード
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
```python
|
56
|
-
|
57
|
-
import matplotlib.pyplot as plt
|
58
|
-
|
59
|
-
import numpy as np
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
def f(x):
|
64
|
-
|
65
|
-
return x**3 - 3 * x + 1
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
xs = np.linspace(-3, 3, 30)
|
70
|
-
|
71
|
-
ys = f(xs)
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
# 各点での傾きを有限差分近似で求める。
|
76
|
-
|
77
|
-
f_prime = np.gradient(ys)
|
78
|
-
|
79
|
-
# sign() 関数をとる。
|
80
|
-
|
81
|
-
print(np.sign(f_prime))
|
82
|
-
|
83
|
-
# diff() をとる。傾きの正負が変わる箇所では 2、
|
84
|
-
|
85
|
-
# それ以外の場所では0になる。
|
86
|
-
|
87
|
-
print(np.diff(np.sign(a)))
|
88
|
-
|
89
|
-
# np.where() でその値が2のインデックスを求める。
|
90
|
-
|
91
|
-
in
|
47
|
+
print('変曲点', infections) # 変曲点 [-1.13793103 0.93103448]
|
92
|
-
|
93
|
-
# 変曲点を求める。
|
94
|
-
|
95
|
-
infections = xs[indices]
|
96
|
-
|
97
|
-
print(infections)
|
98
48
|
|
99
49
|
|
100
50
|
|