#!/usr/bin/env python # coding: utf-8 # # Factoring vector equations # # ## Magnetic due to 2-wires # # ### General equation # # \begin{align} # \vec{\mathbf{B}} = {\mu}I_1 \left( - \frac{y_1}{s_1^2} \hat{x} + \frac{x_1}{s_1^2} \hat{y} \right) # +{\mu}I_2 \left( - \frac{y_2}{s_2^2} \hat{x} + \frac{x_2}{s_2^2} \hat{y} \right) # \end{align} # # ### Same $y$ and $I$ # 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)))) # In[5]: factor = sym.factor(B, (xhat, yhat, I, m)) factor # In[6]: Math(sym.latex(factor)) # 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,)))) # 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)))) # 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} # ### Different $I$ # 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)))) # In[11]: factor = sym.factor(B, (xhat, yhat)) factor # In[12]: sym.latex(factor) # In[13]: Math(sym.latex(factor)) # In[14]: xhat2 = -(I1*s2**2*y + I2*s1**2*y)/(s1**2*s2**2) factor = sym.factor(xhat2, (s1, s2)) factor # In[15]: sym.latex(factor) # In[16]: Math(sym.latex(factor)) # In[17]: yhat2 = (I1*s2**2*x1 + I2*s1**2*x2)/(s1**2*s2**2) factor = sym.factor(yhat2, (s1, s2)) factor # In[18]: sym.latex(factor) # In[19]: Math(sym.latex(factor)) # 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}