In [1]:
import sympy as sym
from IPython.display import Math
In [2]:
syms = sym.symbols("\mu I1 I2 I xhat x1 x2 x yhat y s1 s2 d")
(m, I1, I2, I, xhat, x1, x2, x, yhat, y, s1, s2, d) = syms
In [3]:
B = m * I * (-y/s1**2*xhat + (x-d)/s1**2*yhat) + m * I * (-y/s2**2*xhat + (x+d)/s2**2*yhat)
Quick sanity check:
In [4]:
Math(sym.latex(sym.collect(B, (xhat, yhat))))
Out[4]:
In [5]:
factor = sym.factor(B, (xhat, yhat, I, m))
factor
Out[5]:
In [6]:
Math(sym.latex(factor))
Out[6]:
In [7]:
yhat2 = yhat*(-d*s1**2 + d*s2**2 - s1**2*x - s2**2*x)/(s1**2*s2**2)
Math(sym.latex(sym.factor(yhat2, (yhat,))))
Out[7]:
In [8]:
yhat3 = (-d*s1**2 + d*s2**2 - s1**2*x - s2**2*x)/(s1**2*s2**2)
Math(sym.latex(sym.factor(yhat3, (s1,s2))))
Out[8]:
From these, we get
\begin{align} \frac{s_1^2 y + s_2^2 y}{s_1^2 s_2^2} \hat{x} \end{align}\begin{align} - \frac{\Big(s_{1}^{2} \left(x + d\right) + s_{2}^{2} \left(x - d\right)\Big)}{s_1^2 s_2^2} \hat{y} \end{align}and thus our equation for the magnetic field due to two wires with the same currents:
\begin{align} \vec{\mathbf{B}} = {\mu}I \Bigg( - \bigg( \frac{y}{s_1^2} + \frac{y}{s_2^2} \bigg) \hat{x} + \bigg( \frac{x - d}{s_1^2} + \frac{x + d}{s_2^2} \bigg) \hat{y} \Bigg) \end{align}
In [9]:
B = m * I1 * (-y/s1**2*xhat + x1/s1**2*yhat) + m * I2 * (-y/s2**2*xhat + x2/s2**2*yhat)
Sanity check:
In [10]:
Math(sym.latex(sym.collect(B, (xhat, yhat))))
Out[10]:
In [11]:
factor = sym.factor(B, (xhat, yhat))
factor
Out[11]:
In [12]:
sym.latex(factor)
Out[12]:
In [13]:
Math(sym.latex(factor))
Out[13]:
In [14]:
xhat2 = -(I1*s2**2*y + I2*s1**2*y)/(s1**2*s2**2)
factor = sym.factor(xhat2, (s1, s2))
factor
Out[14]:
In [15]:
sym.latex(factor)
Out[15]:
In [16]:
Math(sym.latex(factor))
Out[16]:
In [17]:
yhat2 = (I1*s2**2*x1 + I2*s1**2*x2)/(s1**2*s2**2)
factor = sym.factor(yhat2, (s1, s2))
factor
Out[17]:
In [18]:
sym.latex(factor)
Out[18]:
In [19]:
Math(sym.latex(factor))
Out[19]:
From this, we get these:
\begin{align} - \frac{I_1 s_2^2 + I_2 s_1^2}{s_1^2 s_2^2} y \hat{x} \end{align}\begin{align} \frac{I_1 s_2^2 x_1 + I_2 s_1^2 x_2}{s_1^2 s_2^2} \hat{y} \end{align}and thus our equation for the magnetic field due to two wires with different currents:
\begin{align} \vec{\mathbf{B}} = {\mu} \Bigg( - \bigg( \frac{I_1 s_2^2 + I_2 s_1^2}{s_1^2 s_2^2} y \bigg) \hat{x} + \bigg( \frac{I_1 s_2^2 x_1 + I_2 s_1^2 x_2}{s_1^2 s_2^2} \bigg) \hat{y} \Bigg) \end{align}\begin{align} = \frac{\mu}{s_1^2 s_2^2} \Big( - y \big( I_1 s_2^2 + I_2 s_1^2 \big) \hat{x} + \big( I_1 s_2^2 (x - d) + I_2 s_1^2 (x + d) \big) \hat{y} \Big) \end{align}