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
| import numpy as np
import matplotlib.pyplot as plot
xmin, ymin, xmax, ymax = -4, -3, 4, 3
X=0
Y = 0
h = 0.01
x = np.arange(xmin,xmax, h)
y = np.arange(ymin,ymax, h)
X, Y = np.meshgrid(X,Y)
particule = [(-1,-2,0),(1, 2,0)]
vect = [np.array([X-xk, Y-yk]) for xk,yk, qk in particule]
dist = [np.linalg.norm(Ve, axis = 0) for Ve in vect]
E = sum(9e9*qk*Ve / D**2 for (xk,yk, qk), Ve,D in zip (particule, vect, dist))
dlimit = 0.5
for D in dist:
E[0][D<dlimit] = np.nan
E[1][D<dlimit] = np.nan
#Représentation
plot.title("Champ electrostatique")
plot.axis('equal')
plot.xlim(xmin,xmax)
plot.ylim(ymin,ymax)
ax = plot.gca()
#Représentation de la secton des fils.
for xk,yk, qk in particule:
radius = 0.05*qk
color = 'red' if qk > 0 else 'blue'
circle = plot.Circle((xk,yk), radius, color=color)
ax.add_artist(circle)
#Représentation des champs électriques.
step = 50
plot.quiver(X[::step, step::], Y[::step, step::], E[0,::step, step::], E[1,::step, step::], scale=None)
plot.draw()
plot.show() |
Partager