forked from exo7math/deepmath-exo7
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgradient_surface_4.py
More file actions
45 lines (30 loc) · 834 Bytes
/
gradient_surface_4.py
File metadata and controls
45 lines (30 loc) · 834 Bytes
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
import numpy as np
import matplotlib.pyplot as plt
# Partie A - ligne de niveaux
n = 100
VX = np.linspace(-1.0, 1.0, n)
VY = np.linspace(-1.0, 1.0, n)
X,Y = np.meshgrid(VX, VY)
def f(x,y):
z = x**2 - y**2
return z
Z = f(X,Y)
# Contour - niveaux donnés avec valeurs
mes_niveaux = np.linspace(-1,1,11)
mes_niveaux = np.append(mes_niveaux,0.1)
mes_niveaux = np.append(mes_niveaux,-0.1)
mes_niveaux = np.sort(mes_niveaux)
plt.contour(X, Y, Z, mes_niveaux)
# Partie B - opposé du gradients
n = 10
VX = np.linspace(-1.0, 1.0, n)
VY = np.linspace(-1.0, 1.0, n)
U,V = np.meshgrid(VX, VY)
q = plt.quiver(VX, VY, -U, V)
plt.quiverkey(q, X=0.3, Y=1.1, U=10,
label='Quiver key, length = 10', labelpos='E')
plt.axis('equal')
plt.axis('off')
plt.tight_layout()
# plt.savefig('gradient-surface-5c.png')
plt.show()