@@ 0,0 1,125 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 76,
+ "id": "68d95f7e-e869-4b32-a487-292d85e5c4ee",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "\u001b[1m equation1 \u001b[0m is i₁⋅(6.0 - 8.0⋅ⅉ) + (6.0 - 8.0⋅ⅉ)⋅(i₁ - i₂) - 675.0 - 389.711431\n",
+ "702997⋅ⅉ\n",
+ "\u001b[1m equation2 \u001b[0m is i₂⋅(6.0 - 8.0⋅ⅉ) + (6.0 - 8.0⋅ⅉ)⋅(-i₁ + i₂) + 779.422863405995⋅\n",
+ "ⅉ\n",
+ "\u001b[1m solutions \u001b[0m is [{i₁: 27.0 + 36.0⋅ⅉ, i₂: 44.6769145362398 - 5.38268590217986⋅ⅉ}\n",
+ "]\n",
+ "\u001b[1m This will print the symbols of the variable, not the variable. Look at your symbols above. \u001b[0m\n",
+ "\u001b[1m i1 \u001b[0m rectangular form is (27.00000000000003+35.99999999999998j)\n",
+ "\u001b[1m i1 \u001b[0m phasor form is 45.0 ∠ 53.13°\n",
+ "\n",
+ "\u001b[1m i2 \u001b[0m rectangular form is (44.67691453623981-5.38268590217986j)\n",
+ "\u001b[1m i2 \u001b[0m phasor form is 45.0 ∠ -6.87°\n",
+ "\n",
+ "\u001b[1m i2-i1 \u001b[0m rectangular form is (17.676914536239785-41.38268590217984j)\n",
+ "\u001b[1m i2-i1 \u001b[0m phasor form is 45.0 ∠ -66.87°\n",
+ "\n",
+ "\u001b[1m i2 * -1 \u001b[0m rectangular form is (-44.67691453623981+5.38268590217986j)\n",
+ "\u001b[1m i2 * -1 \u001b[0m phasor form is 45.0 ∠ 173.13°\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "import electricpy as ep\n",
+ "from sympy import symbols, Eq, solve, I\n",
+ "from varname import varname\n",
+ "from __future__ import print_function\n",
+ "from io import StringIO\n",
+ "import sys\n",
+ "from sympy import init_session\n",
+ "\n",
+ "init_session(quiet=True) \n",
+ "#TODO fix making printing and enetering more expressions more elegant\n",
+ "\n",
+ "def equation_print(name, variable):\n",
+ " # weird codes are just bolding and unbolding\n",
+ " print('\\033[1m', name, '\\033[0m', 'is ', end=\"\")\n",
+ " pprint(variable, imaginary_unit = \"j\")\n",
+ " \n",
+ "def print_rect_and_phasor(name, value):\n",
+ " value = complex(value)\n",
+ " print('\\033[1m', name, '\\033[0m', \"rectangular form is\", value)\n",
+ " print('\\033[1m', name, '\\033[0m', \"phasor form is \", end =\"\")\n",
+ " ep.cprint(value)\n",
+ " print()\n",
+ " \n",
+ "#declare what things you want to solve for. If I have i1, i2, v1, and v2, but I only need i1 and i2, \n",
+ "#I will only add those to varlist\n",
+ "varlist = [i1,i2]\n",
+ "\n",
+ "i1 = symbols('i1')\n",
+ "i2 = symbols('i2')\n",
+ "\n",
+ "#write your equations here \n",
+ "equations = [equation1, equation2]\n",
+ "equation1 = (ep.phasor(-450, 0) + ((6-8j) * (i1)) + ((6-8j) * (i1-i2)) + ep.phasor(450, -120))\n",
+ "equation_print('equation1', equation1)\n",
+ "\n",
+ "equation2 = (ep.phasor(-450,-120) + (6-8j) * (i2-i1) + i2 * (6-8j) + (ep.phasor(450,120)))\n",
+ "equation_print('equation2', equation2)\n",
+ "\n",
+ "#solve the equations\n",
+ "solutions = solve(equations, varlist, dict=True)\n",
+ "equation_print('solutions', solutions)\n",
+ "\n",
+ "#print the solutions\n",
+ "print('\\033[1m', \"This will print the symbols of the variable, not the variable. Look at your symbols above.\", '\\033[0m')\n",
+ "solutions = solutions[0]\n",
+ "for count, value in enumerate(varlist):\n",
+ " temp = solutions[value]\n",
+ " temp = complex(temp)\n",
+ " print_rect_and_phasor(value,temp)\n",
+ " \n",
+ "\n",
+ "#Get whatever else you need\n",
+ "#TODO: make this more elegant\n",
+ "s = solutions\n",
+ "print_rect_and_phasor('i2-i1', s[i2]-s[i1])\n",
+ "print_rect_and_phasor('i2 * -1', s[i2] * -1)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "f569a832-f0b8-422b-8075-7ba70211a085",
+ "metadata": {},
+ "source": [
+ "y"
+ ]
+ }
+ ],
+ "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.11.7"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}