# fields.ipynb

In [1]:
from sympy import symbols, pi

In [2]:
rA, rB, rP = symbols('r_A, r_B, r_P')
display(rA, rB, rP)

$\displaystyle r_{A}$
$\displaystyle r_{B}$
$\displaystyle r_{P}$
In [3]:
epsilon0 = symbols('epsilon_0')
epsilon0

Out[3]:
$\displaystyle \epsilon_{0}$
In [4]:
k = 1/(4*pi*epsilon0)
k

Out[4]:
$\displaystyle \frac{1}{4 \pi \epsilon_{0}}$
In [5]:
qA, qB, qC = symbols('q_A, q_B, q_C')
display(qA, qB, qC)

$\displaystyle q_{A}$
$\displaystyle q_{B}$
$\displaystyle q_{C}$
In [6]:
xA, yA, xB, yB, xP, yP  = symbols('x_A, y_A, x_B, y_B, x_P, y_P')
display(xA, yA, xB, yB, xP, yP)

$\displaystyle x_{A}$
$\displaystyle y_{A}$
$\displaystyle x_{B}$
$\displaystyle y_{B}$
$\displaystyle x_{P}$
$\displaystyle y_{P}$
In [7]:
from sympy.vector import CoordSys3D, Vector

In [8]:
N = CoordSys3D('N')
N

Out[8]:
$\displaystyle CoordSys3D\left(N, \left( \left[\begin{matrix}1 & 0 & 0\\0 & 1 & 0\\0 & 0 & 1\end{matrix}\right], \ \mathbf{\hat{0}}\right)\right)$
In [9]:
rA = xA * N.i + yA * N.j
rA

Out[9]:
$\displaystyle (x_{A})\mathbf{\hat{i}_{N}} + (y_{A})\mathbf{\hat{j}_{N}}$
In [10]:
rB = xB * N.i + yB * N.j
rB

Out[10]:
$\displaystyle (x_{B})\mathbf{\hat{i}_{N}} + (y_{B})\mathbf{\hat{j}_{N}}$
In [11]:
rP = xP * N.i + yP * N.j
rP

Out[11]:
$\displaystyle (x_{P})\mathbf{\hat{i}_{N}} + (y_{P})\mathbf{\hat{j}_{N}}$
In [12]:
rAP = rP - rA
rAP

Out[12]:
$\displaystyle (- x_{A} + x_{P})\mathbf{\hat{i}_{N}} + (- y_{A} + y_{P})\mathbf{\hat{j}_{N}}$
In [13]:
EA = k * (qA/rAP.magnitude()**3 )*rAP
EA

Out[13]:
$\displaystyle (\frac{q_{A} \left(- x_{A} + x_{P}\right)}{4 \pi \epsilon_{0} \left(\left(- x_{A} + x_{P}\right)^{2} + \left(- y_{A} + y_{P}\right)^{2}\right)^{\frac{3}{2}}})\mathbf{\hat{i}_{N}} + (\frac{q_{A} \left(- y_{A} + y_{P}\right)}{4 \pi \epsilon_{0} \left(\left(- x_{A} + x_{P}\right)^{2} + \left(- y_{A} + y_{P}\right)^{2}\right)^{\frac{3}{2}}})\mathbf{\hat{j}_{N}}$
In [14]:
rBP = rP - rB
rBP

Out[14]:
$\displaystyle (- x_{B} + x_{P})\mathbf{\hat{i}_{N}} + (- y_{B} + y_{P})\mathbf{\hat{j}_{N}}$
In [15]:
EB = k * (qB/rBP.magnitude()**3 )*rBP
EB

Out[15]:
$\displaystyle (\frac{q_{B} \left(- x_{B} + x_{P}\right)}{4 \pi \epsilon_{0} \left(\left(- x_{B} + x_{P}\right)^{2} + \left(- y_{B} + y_{P}\right)^{2}\right)^{\frac{3}{2}}})\mathbf{\hat{i}_{N}} + (\frac{q_{B} \left(- y_{B} + y_{P}\right)}{4 \pi \epsilon_{0} \left(\left(- x_{B} + x_{P}\right)^{2} + \left(- y_{B} + y_{P}\right)^{2}\right)^{\frac{3}{2}}})\mathbf{\hat{j}_{N}}$
In [16]:
E = EA + EB
E

Out[16]:
$\displaystyle (\frac{q_{A} \left(- x_{A} + x_{P}\right)}{4 \pi \epsilon_{0} \left(\left(- x_{A} + x_{P}\right)^{2} + \left(- y_{A} + y_{P}\right)^{2}\right)^{\frac{3}{2}}} + \frac{q_{B} \left(- x_{B} + x_{P}\right)}{4 \pi \epsilon_{0} \left(\left(- x_{B} + x_{P}\right)^{2} + \left(- y_{B} + y_{P}\right)^{2}\right)^{\frac{3}{2}}})\mathbf{\hat{i}_{N}} + (\frac{q_{A} \left(- y_{A} + y_{P}\right)}{4 \pi \epsilon_{0} \left(\left(- x_{A} + x_{P}\right)^{2} + \left(- y_{A} + y_{P}\right)^{2}\right)^{\frac{3}{2}}} + \frac{q_{B} \left(- y_{B} + y_{P}\right)}{4 \pi \epsilon_{0} \left(\left(- x_{B} + x_{P}\right)^{2} + \left(- y_{B} + y_{P}\right)^{2}\right)^{\frac{3}{2}}})\mathbf{\hat{j}_{N}}$
In [ ]: