-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisocline.py
More file actions
38 lines (28 loc) · 1.01 KB
/
isocline.py
File metadata and controls
38 lines (28 loc) · 1.01 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
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('TkAgg')
XLIM = (-4, 4)
YLIM = (-4, 4)
def f(x, y):
""" Правая часть ДУ y'=f(x, y) """
return -x/y
def main():
fig = plt.figure()
ax = plt.axes(xlim=XLIM, ylim=YLIM)
ax.set_aspect('equal')
# оси координат
ax.hlines(0, *XLIM, lw=0.5)
ax.vlines(0, *YLIM, lw=0.5)
# здесь можно изменить плотность сетки, в узлах которой строятся векторы
x = np.linspace(*XLIM, 21)
y = np.linspace(*YLIM, 21)
X, Y = np.meshgrid(x, y)
# нормирующий множитель, приводит векторы поля к единой длине
norm = np.hypot(1, f(X, Y))
# поле направлений
kwargs = {'angles': 'xy', 'width': 0.002, 'pivot': 'mid'}
ax.quiver(X, Y, 1/norm, f(X, Y)/norm, **kwargs)
plt.show()
if __name__ == "__main__":
main()