For in
For in
2 d = 0.25
3 v0 = 0.1
4 x0 = 0.1
5 dt = 0.01
6 T = 8000000
7 period = 2*np.pi/w
8
9 for f in [0.3, 0.4]:
10 t, sol = RK4( duffing, [0, T*dt], (f, d, w), dt, [x0, v0] )
11 x, v = sol[:,0], sol[:,1]
12 ts = np.abs((t % period) - period ) < dt
13
14 fig = plt.figure(figsize=(20,4))
15 gs=fig.add_gridspec(2,3)
16 ax1=fig.add_subplot(gs[0,0])
17 ax2=fig.add_subplot(gs[1,0])
18 ax3=fig.add_subplot(gs[:,1])
19 ax4=fig.add_subplot(gs[:,2])
20 fig.suptitle(f'$x_0={x[0]}, v_0={v[0]}, \delta={d}, f={f}$', fontsize=30, y=1.01)
21
22 ax1.plot(t[:20000], x[:20000], lw=0.6, color='blue')
23 ax1.set_xlabel("Time (t)")
24 ax1.set_ylabel("Position (x)")
25
26 ax2.plot(t[:20000], v[:20000], lw=0.6, color='orange')
27 ax2.set_xlabel("Time (t)")
28 ax2.set_ylabel("Velocity (v)")
29
30 ax3.plot(x[:20000], v[:20000], lw=0.6, color='purple')
31 ax3.set_title("Phase Space (x vs v)")
32 ax3.set_xlabel("Position (x)")
33 ax3.set_ylabel("Velocity (v)")
34
35 ax4.plot(x[ts], v[ts],'r,',ms=0.4)
36 ax4.set_title("Poincare Space (x vs v)")
37 ax4.set_xlabel("Position (x)")
38 ax4.set_ylabel("Velocity (v)")
39 plt.tight_layout()
40 plt.show()
In [5]: 1 w = 1
2 d = 0.25
3 f = 0.3
4 dx_0 = 0.1
5 x_0 = 0.195
6 dt = 0.01
7 T = 50000
8 t_span = [0, T*dt]
9
10 t, sol = RK4( duffing, t_span, (f, d, w), dt, [x_0, dx_0] )
11 x, v = sol[:,0], sol[:,1]
12
13 for n in range(46000):
14 if n % 1000 == 0:
15 clear_output(wait=True)
16 fig = plt.figure(figsize=(20,6))
17 gs=fig.add_gridspec(2,4)
18 ax1=fig.add_subplot(gs[0,0:2])
19 ax2=fig.add_subplot(gs[1,0:2])
20 ax3=fig.add_subplot(gs[:,2:4])
21 fig.suptitle(f'$t={n*dt}s | x_0={x[0]}, v_0={v[0]}, \delta={d}, f={f}$', fontsize=30, y=1.01)
22
23 ax1.clear()
24 ax1.plot(t[:n], x[:n], lw=0.6, color='blue')
25 ax1.set_title("Position (x) over time")
26 ax1.set_xlabel("Time (t)")
27 ax1.set_ylabel("Position (x)")
28
29 ax2.clear()
30 ax2.plot(t[:n], v[:n], lw=0.6, color='orange')
31 ax2.set_title("Velocity (v) over time")
32 ax2.set_xlabel("Time (t)")
33 ax2.set_ylabel("Velocity (v)")
34
35 ax3.clear()
36 ax3.plot(x[:n], v[:n], lw=0.6, color='purple')
37 ax3.set_title("Phase Space (x vs v)")
38 ax3.set_xlabel("Position (x)")
39 ax3.set_ylabel("Velocity (v)")
40
41 plt.tight_layout()
42 plt.show()