In [1]:
from sympy import *
from sympy.vector import CoordSys3D, Vector
import matplotlib.pyplot as plt
import numpy as np
In [2]:
E, epsilon_0, q, q_1, q_2 = symbols('E, epsilon_0, q, q_1, q_2')
r, vec_r, univec_r = symbols('r, {\overrightarrow{{r}}} , {\widehat{{r}}}')
r_A, vec_r_A, univec_r_A = symbols('r_A, {\overrightarrow{{r_A}}} , {\widehat{{r_A}}}')
r_B, vec_r_B, univec_r_B = symbols('r_B, {\overrightarrow{{r_B}}} , {\widehat{{r_B}}}')
In [3]:
Electric_field_Law = Eq(E, 1/(4*pi*epsilon_0) * (q/r**3) * vec_r)
Electric_field_Law
Out[3]:
In [4]:
value_of_epsilon_0 = Eq(epsilon_0, 8.85148781762039e-12)
value_of_epsilon_0
Out[4]:
In [5]:
N = CoordSys3D('N')
In [55]:
A = np.array([3, -5])
B = np.array([-5, 2])
In [56]:
distanceVec = B - A
distanceSca = np.linalg.norm(distanceVec)
In [57]:
plt.figure(figsize = (6, 6))
plt.plot(A[0], A[1], marker = 'o', color = 'blue', markersize = 8, label = 'A - q = 2$C$')
plt.annotate('A', xy = (A[0] + 0.5, A[1]), fontsize = 14)
plt.plot(B[0], B[1], marker = 'o', color = 'red', markersize = 8, label = 'B - Field strength at B')
plt.annotate('B', xy = (B[0] + 0.5, B[1]), fontsize = 14)
plt.arrow(A[0], A[1], distanceVec[0], distanceVec[1], width = 0.15, color = 'lime', label = distanceVec, length_includes_head = True)
plt.annotate(round(distanceSca, 2), xy = (((B[0] + A[0])/2) + 0.5, (B[1] + A[1])/2), fontsize = 14)
#required
plt.legend()
plt.xlim(-6, 6)
plt.ylim(-6, 6)
plt.xticks(np.arange(-6, 7))
plt.yticks(np.arange(-6, 7))
plt.grid()
plt.gca().set_aspect('equal')
In [58]:
vec_r_A = A[0]*N.i + A[1]*N.j
vec_r_A
Out[58]:
In [59]:
vec_r_B = B[0]*N.i + B[1]*N.j
vec_r_B
Out[59]:
In [60]:
vec_r_eq = Eq(vec_r, vec_r_B - vec_r_A, evaluate = False)
vec_r_eq
Out[60]:
In [61]:
r_eq = Eq(r, (vec_r_B - vec_r_A).magnitude())
r_eq
Out[61]:
In [62]:
q_eq = Eq(q, 2)
q_eq
Out[62]:
In [65]:
field1 = Electric_field_Law.subs({
epsilon_0: value_of_epsilon_0.rhs,
q: q_eq.rhs,
vec_r: vec_r_eq.rhs,
r: r_eq.rhs
})
field1.n(4)
Out[65]:
In [67]:
plt.figure(figsize = (6, 6))
plt.plot(A[0], A[1], marker = 'o', color = 'blue', markersize = 8, label = 'A - q = 2$C$')
plt.annotate('A', xy = (A[0] + 0.5, A[1]), fontsize = 14)
plt.plot(B[0], B[1], marker = 'o', color = 'red', markersize = 8, label = f'B - ${latex(field1.n(4))}$')
plt.annotate('B', xy = (B[0] + 0.5, B[1]), fontsize = 14)
plt.arrow(A[0], A[1], distanceVec[0], distanceVec[1], width = 0.15, color = 'lime', label = distanceVec, length_includes_head = True)
plt.annotate(round(distanceSca, 2), xy = (((B[0] + A[0])/2) + 0.5, (B[1] + A[1])/2), fontsize = 14)
#required
plt.legend()
plt.xlim(-6, 6)
plt.ylim(-6, 6)
plt.xticks(np.arange(-6, 7))
plt.yticks(np.arange(-6, 7))
plt.grid()
plt.gca().set_aspect('equal')
In [ ]:
In [ ]: