forked from sijichun/MathStatsCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrownian.py
More file actions
68 lines (64 loc) · 1.79 KB
/
Copy pathbrownian.py
File metadata and controls
68 lines (64 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import numpy as np
import numpy.random as nprd
t=np.linspace(0.0,5.0,5000)
B1=np.zeros(len(t))
B2=np.zeros(len(t))
B3=np.zeros(len(t))
B4=np.zeros(len(t))
B5=np.zeros(len(t))
B6=np.zeros(len(t))
b1=b2=b3=b4=b5=b6=0
epsilon=np.sqrt(t[1]-t[0])
for tt in range(len(t)):
B1[tt]=b1
b1=b1+nprd.normal(0,epsilon)
B2[tt]=b2
b2=b2+nprd.normal(0,epsilon)
B3[tt]=b3
b3=b3+nprd.normal(0,epsilon)
B4[tt]=b4
b4=b4+nprd.normal(0,epsilon)
B5[tt]=b5
b5=b5+nprd.normal(0,epsilon)
B6[tt]=b6
b6=b6+nprd.normal(0,epsilon)
import matplotlib.pyplot as plt
# 设定图像大小
plt.rcParams['figure.figsize'] = (10.0, 10.0)
plt.figure(0)
plt.plot(t,B1,label=r'Brownian Motion1',color='blue')
plt.plot(t,B2,label=r'Brownian Motion2',color='red')
plt.plot(t,B3,label=r'Brownian Motion3',color='pink')
plt.plot(t,B4,label=r'Brownian Motion4',color='green')
plt.plot(t,B5,label=r'Brownian Motion5',color='orange')
plt.plot(t,B6,label=r'Brownian Motion6',color='yellow')
plt.legend(loc='upper left', frameon=True)
plt.savefig("brownian_motion.eps")
t=np.linspace(0.0,5.0,10000)
B1=np.zeros(len(t))
B2=np.zeros(len(t))
B3=np.zeros(len(t))
B4=np.zeros(len(t))
B5=np.zeros(len(t))
B6=np.zeros(len(t))
b1=b2=b3=b4=b5=b6=0
epsilon=np.sqrt(t[1]-t[0])
for tt in range(len(t)):
B1[tt]=b1
b1=b1+nprd.normal(0,epsilon)
B2[tt]=b2
b2=b2+nprd.normal(0,epsilon)
B3[tt]=b3
b3=b3+nprd.normal(0,epsilon)
B4[tt]=b4
b4=b4+nprd.normal(0,epsilon)
B5[tt]=b5
b5=b5+nprd.normal(0,epsilon)
B6[tt]=b6
b6=b6+nprd.normal(0,epsilon)
plt.figure(1)
plt.plot(B1,B2,label=r'Brownian Motion1',color='blue')
plt.plot(B3,B4,label=r'Brownian Motion2',color='red')
plt.plot(B5,B6,label=r'Brownian Motion3',color='green')
plt.legend(loc='upper left', frameon=True)
plt.savefig("brownian_motion_2d.eps")