{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Factoring vector equations\n", "\n", "## Magnetic due to 2-wires\n", "\n", "### General equation\n", "\n", "\\begin{align} \n", "\\vec{\\mathbf{B}} = {\\mu}I_1 \\left( - \\frac{y_1}{s_1^2} \\hat{x} + \\frac{x_1}{s_1^2} \\hat{y} \\right)\n", " +{\\mu}I_2 \\left( - \\frac{y_2}{s_2^2} \\hat{x} + \\frac{x_2}{s_2^2} \\hat{y} \\right)\n", "\\end{align}\n", "\n", "### Same $y$ and $I$" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import sympy as sym\n", "from IPython.display import Math" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "syms = sym.symbols(\"\\mu I1 I2 I xhat x1 x2 x yhat y s1 s2 d\")\n", "(m, I1, I2, I, xhat, x1, x2, x, yhat, y, s1, s2, d) = syms" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "B = m * I * (-y/s1**2*xhat + (x-d)/s1**2*yhat) + m * I * (-y/s2**2*xhat + (x+d)/s2**2*yhat)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Quick sanity check:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$I \\mu \\left(- \\frac{\\hat{x} y}{s_{1}^{2}} + \\frac{\\hat{y}}{s_{1}^{2}} \\left(- d + x\\right)\\right) + I \\mu \\left(- \\frac{\\hat{x} y}{s_{2}^{2}} + \\frac{\\hat{y}}{s_{2}^{2}} \\left(d + x\\right)\\right)$$" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Math(sym.latex(sym.collect(B, (xhat, yhat))))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "-I*\\mu*(xhat*(s1**2*y + s2**2*y) + yhat*(-d*s1**2 + d*s2**2 - s1**2*x - s2**2*x))/(s1**2*s2**2)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "factor = sym.factor(B, (xhat, yhat, I, m))\n", "factor" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$- \\frac{I \\mu}{s_{1}^{2} s_{2}^{2}} \\left(\\hat{x} \\left(s_{1}^{2} y + s_{2}^{2} y\\right) + \\hat{y} \\left(- d s_{1}^{2} + d s_{2}^{2} - s_{1}^{2} x - s_{2}^{2} x\\right)\\right)$$" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Math(sym.latex(factor))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$\\frac{\\hat{y}}{s_{1}^{2} s_{2}^{2}} \\left(- d s_{1}^{2} + d s_{2}^{2} - s_{1}^{2} x - s_{2}^{2} x\\right)$$" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "yhat2 = yhat*(-d*s1**2 + d*s2**2 - s1**2*x - s2**2*x)/(s1**2*s2**2)\n", "Math(sym.latex(sym.factor(yhat2, (yhat,))))" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$- \\frac{1}{s_{1}^{2} s_{2}^{2}} \\left(s_{1}^{2} \\left(d + x\\right) + s_{2}^{2} \\left(- d + x\\right)\\right)$$" ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "yhat3 = (-d*s1**2 + d*s2**2 - s1**2*x - s2**2*x)/(s1**2*s2**2)\n", "Math(sym.latex(sym.factor(yhat3, (s1,s2))))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "From these, we get\n", "\n", "\\begin{align} \n", "\\frac{s_1^2 y + s_2^2 y}{s_1^2 s_2^2} \\hat{x} \n", "\\end{align}\n", "\n", "\\begin{align} \n", "- \\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} \n", "\\end{align}\n", "\n", "and thus our equation for the magnetic field due to two wires with the same currents:\n", "\n", "\\begin{align} \n", "\\vec{\\mathbf{B}} = {\\mu}I \\Bigg( - \\bigg( \\frac{y}{s_1^2} + \\frac{y}{s_2^2} \\bigg) \\hat{x}\n", " + \\bigg( \\frac{x - d}{s_1^2} + \\frac{x + d}{s_2^2} \\bigg) \\hat{y} \\Bigg)\n", "\\end{align}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Different $I$" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [], "source": [ "B = m * I1 * (-y/s1**2*xhat + x1/s1**2*yhat) + m * I2 * (-y/s2**2*xhat + x2/s2**2*yhat)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sanity check:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$I_{1} \\mu \\left(\\frac{x_{1} \\hat{y}}{s_{1}^{2}} - \\frac{\\hat{x} y}{s_{1}^{2}}\\right) + I_{2} \\mu \\left(\\frac{x_{2} \\hat{y}}{s_{2}^{2}} - \\frac{\\hat{x} y}{s_{2}^{2}}\\right)$$" ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Math(sym.latex(sym.collect(B, (xhat, yhat))))" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "-\\mu*(xhat*(I1*s2**2*y + I2*s1**2*y) + yhat*(-I1*s2**2*x1 - I2*s1**2*x2))/(s1**2*s2**2)" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "factor = sym.factor(B, (xhat, yhat))\n", "factor" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'- \\\\frac{\\\\mu}{s_{1}^{2} s_{2}^{2}} \\\\left(\\\\hat{x} \\\\left(I_{1} s_{2}^{2} y + I_{2} s_{1}^{2} y\\\\right) + \\\\hat{y} \\\\left(- I_{1} s_{2}^{2} x_{1} - I_{2} s_{1}^{2} x_{2}\\\\right)\\\\right)'" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sym.latex(factor)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$- \\frac{\\mu}{s_{1}^{2} s_{2}^{2}} \\left(\\hat{x} \\left(I_{1} s_{2}^{2} y + I_{2} s_{1}^{2} y\\right) + \\hat{y} \\left(- I_{1} s_{2}^{2} x_{1} - I_{2} s_{1}^{2} x_{2}\\right)\\right)$$" ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Math(sym.latex(factor))" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "-y*(I1*s2**2 + I2*s1**2)/(s1**2*s2**2)" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xhat2 = -(I1*s2**2*y + I2*s1**2*y)/(s1**2*s2**2)\n", "factor = sym.factor(xhat2, (s1, s2))\n", "factor" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'- \\\\frac{y}{s_{1}^{2} s_{2}^{2}} \\\\left(I_{1} s_{2}^{2} + I_{2} s_{1}^{2}\\\\right)'" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sym.latex(factor)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$- \\frac{y}{s_{1}^{2} s_{2}^{2}} \\left(I_{1} s_{2}^{2} + I_{2} s_{1}^{2}\\right)$$" ], "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Math(sym.latex(factor))" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "(I1*s2**2*x1 + I2*s1**2*x2)/(s1**2*s2**2)" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "yhat2 = (I1*s2**2*x1 + I2*s1**2*x2)/(s1**2*s2**2)\n", "factor = sym.factor(yhat2, (s1, s2))\n", "factor" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'\\\\frac{1}{s_{1}^{2} s_{2}^{2}} \\\\left(I_{1} s_{2}^{2} x_{1} + I_{2} s_{1}^{2} x_{2}\\\\right)'" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sym.latex(factor)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "$$\\frac{1}{s_{1}^{2} s_{2}^{2}} \\left(I_{1} s_{2}^{2} x_{1} + I_{2} s_{1}^{2} x_{2}\\right)$$" ], "text/plain": [ "" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Math(sym.latex(factor))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "From this, we get these:\n", "\n", "\\begin{align}\n", "- \\frac{I_1 s_2^2 + I_2 s_1^2}{s_1^2 s_2^2} y \\hat{x} \n", "\\end{align}\n", "\n", "\\begin{align} \n", "\\frac{I_1 s_2^2 x_1 + I_2 s_1^2 x_2}{s_1^2 s_2^2} \\hat{y} \n", "\\end{align}\n", "\n", "and thus our equation for the magnetic field due to two wires with different currents:\n", "\n", "\\begin{align} \n", "\\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}\n", " + \\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)\n", "\\end{align}\n", "\n", "\\begin{align} \n", "= \\frac{\\mu}{s_1^2 s_2^2} \\Big( - y \\big( I_1 s_2^2 + I_2 s_1^2 \\big) \\hat{x}\n", " + \\big( I_1 s_2^2 (x - d) + I_2 s_1^2 (x + d) \\big) \\hat{y} \\Big)\n", "\\end{align}" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.2" } }, "nbformat": 4, "nbformat_minor": 0 }