-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchar_div.py
executable file
·53 lines (40 loc) · 938 Bytes
/
char_div.py
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
#!/usr/bin/env python3
import numpy as np
import os
import sys
import matplotlib.pyplot as plt
import scipy.integrate
from util import get_path, savefig
xc = 1
def C1(x, t):
return x - xc
def C2(x, t):
return t - 1
t = np.linspace(0, 3, 500)
def traj_exact_1(x0):
return xc + (x0 - xc) * np.exp(t)
def traj_exact_2(x0):
return xc + 0.5 * t ** 2 - t
def traj(c, x0):
x = scipy.integrate.odeint(c, x0, t)
return x
fig, ax = plt.subplots()
ax.set_xlim(0, 2)
ax.set_ylim(0, 2)
for x0 in np.linspace(0, 2, 21):
ax.plot(traj(C1, x0), t, c='C0')
#ax.plot(traj_exact_1(x0), t, c='C1')
ax.set_xlabel('x')
ax.set_ylabel('t')
savefig(fig)
plt.close(fig)
fig, ax = plt.subplots()
ax.set_xlim(0, 2)
ax.set_ylim(0, 2)
for x0 in np.linspace(0, 2, 21):
ax.plot(traj(C2, x0), t, c='C0')
#ax.plot(traj_exact_2(x0), t, c='C1')
ax.set_xlabel('x')
ax.set_ylabel('t')
savefig(fig, suff='_2')
plt.close(fig)