回答編集履歴
2
追記
test
CHANGED
@@ -27,3 +27,47 @@
|
|
27
27
|
|
28
28
|
|
29
29
|
![イメージ説明](502d6b487452f2818b7d67d190e3b03a.png)
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
==追記==
|
34
|
+
|
35
|
+
積分範囲はy1,y2の関数で取りうる値域をそのまま使うのではだめですか?
|
36
|
+
|
37
|
+
その場合、Xのmax/minを計算しなくても済みますが。
|
38
|
+
|
39
|
+
```python
|
40
|
+
|
41
|
+
# locとscaleの値は仮想のもの
|
42
|
+
|
43
|
+
x = np.linspace(0,10,5000) #5000点に増やした
|
44
|
+
|
45
|
+
y1 = stats.norm.pdf(x,loc=2,scale=0.5)
|
46
|
+
|
47
|
+
y2 = stats.norm.pdf(x,loc=3,scale=0.8)
|
48
|
+
|
49
|
+
y3 = np.minimum(y1,y2)
|
50
|
+
|
51
|
+
abInteg=integrate.simps(y3, x) #AxBの面積を求める
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
plt.plot(x,y1,label='func A')
|
56
|
+
|
57
|
+
plt.plot(x,y2,label='func B')
|
58
|
+
|
59
|
+
plt.fill(x,y3,label="A*B")
|
60
|
+
|
61
|
+
AxB='AxB area={}'.format(abInteg)
|
62
|
+
|
63
|
+
plt.text(5,0.6,AxB)
|
64
|
+
|
65
|
+
plt.legend()
|
66
|
+
|
67
|
+
plt.show()
|
68
|
+
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
![イメージ説明](ccc7451f19b8efcbac73bdbf81b99983.png)
|
1
コードを追記
test
CHANGED
@@ -1 +1,29 @@
|
|
1
1
|
どこまでの精度が必要か分かりませんが、提示のコードからだと、xの範囲でy1とy2のリストについて小さい方の値をとったy3というリストを作って面積を求めるのではだめですか?
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
```python
|
6
|
+
|
7
|
+
x = np.linspace(-10,10,100)
|
8
|
+
|
9
|
+
y1 = stats.norm.pdf(x,loc=2,scale=0.5)
|
10
|
+
|
11
|
+
y2 = stats.norm.pdf(x,loc=3,scale=0.8)
|
12
|
+
|
13
|
+
y3 = np.minimum(y1,y2)
|
14
|
+
|
15
|
+
plt.plot(x,y1,label='func A')
|
16
|
+
|
17
|
+
plt.plot(x,y2,label='func B')
|
18
|
+
|
19
|
+
plt.plot(x,y3,label="A*B")
|
20
|
+
|
21
|
+
plt.legend()
|
22
|
+
|
23
|
+
plt.show()
|
24
|
+
|
25
|
+
```
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
![イメージ説明](502d6b487452f2818b7d67d190e3b03a.png)
|