{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## キルヒホッフの法則\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 連立方程式をSageで解く\n", "\n", "$ R_1, R_2 $を時計回りに流れる電流 $I_1$と$R_3, R_4, R2$を時計周りに流れる電流$I_2$とすると、\n", "\n", "- $R_2$ を通過する電流 $I_{R2}$は、$I_1 - I_2$であるからキルヒホッフの電圧法則から最初の式が導かれる\n", "- $ R_1, R_2, R_3$の交点の電圧$ V_2 $が等しいことから2番目の式が導かれれる\n", "\n", "$$\n", "\t\t\\left\\{ \n", " \\begin{eqnarray}\n", "\t\t\t(R_1 + R_2) I_1 - R_2 I_2& = & V_1 \\\\\n", "\t\t\t-R_2 I_1 + (R_2 + R_3 + R_4) I_2 & = & 0\n", "\t\t\\end{eqnarray} \n", " \\right.\n", "$$\n", "\n", "これをSageで表すと以下のようになります。" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[I1*(R1 + R2) - I2*R2 == V1, I2*(R2 + R3 + R4) - I1*R2 == 0]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "I1, I2, V1, R1, R2, R3, R4 = var('I1 I2 V1 R1 R2 R3 R4')\n", "eq = [\n", " (R1 + R2)*I1 - R2*I2 == V1,\n", " -R2*I1 + (R2 + R3 + R4)*I2 == 0\n", "]\n", "\n", "show(eq)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[I1 == (R2 + R3 + R4)*V1/((R1 + R3 + R4)*R2 + R1*(R3 + R4)),\n", " I2 == R2*V1/((R1 + R3 + R4)*R2 + R1*(R3 + R4))]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# solveの結果は配列でかえされるので、最初の解のみを使用する\n", "sol = solve(eq, [I1, I2])[0]\n", "show(sol)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.00377358490566038\n", "0.000943396226415094\n" ] } ], "source": [ "values = {V1:1, R1: 100, R2:220, R3:330, R4:330}\n", "#  I1の式(sol[0])にvaluesを代入し、I1の値(右辺rhs)の値を数値で表示する\n", "print sol[0].substitute(values).rhs().n()\n", "# 同様にI2の値を求める\n", "print sol[1].substitute(values).rhs().n()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$V_2, V_3$の値は以下のように求まります。" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.622641509433962\n", "0.311320754716981\n" ] } ], "source": [ "# I1 は、1番目の解の右辺なので、sol[0].rhs()となります\n", "V2 = V1 - sol[0].rhs()*R1\n", "print V2.substitute(values).n()\n", "# 同様に\n", "V3 = V1 - sol[0].rhs()*R1 - sol[1].rhs()*R3\n", "print V3.substitute(values).n()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## テブナンの定理\n", "上記の解をテブナンの定理を使って解いたのが、トラ技の図4です。\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "点線で分割した左側にテブナンの定理を使って、$R_1, R_2$で分圧された電圧が$V'_1$となり、$R_1, R_2$の並列抵抗$R'$で表されます。" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# 並列抵抗を計算する\n", "def R_parallel(*Rs):\n", " R = sum([ 1/r for r in Rs])\n", " return 1/R\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "並列抵抗を$R_a$、分圧された電圧を$V_{1a}$とすると、以下のように求まります。" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "R2*V1/(R1 + R2)\n", "1/(1/R1 + 1/R2)\n" ] } ], "source": [ "V1a = V1*R2/(R1+R2)\n", "Ra = R_parallel(R1, R2)\n", "print V1a\n", "print Ra" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "R2*(R3 + R4)*V1/((R1 + R2)*(R3 + R4 + 1/(1/R1 + 1/R2)))\n" ] }, { "data": { "text/plain": [ "0.622641509433962" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "V2 = V1a*(R3+R4)/(Ra + R3 + R4)\n", "print V2\n", "V2.substitute(values).n()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "SageMath 7.5.1", "language": "", "name": "sagemath" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.13" } }, "nbformat": 4, "nbformat_minor": 0 }