{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# HW6 Q5\n", "### EECS 16A: Designing Information Devices and Systems I, Fall 2016" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Circuit solver\n", "In this question we will write a program that solves circuits methodically, able to include both voltage and current souces." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\n", "from numpy import linalg\n", "from __future__ import print_function" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(i) Write the incidence matrix F for the graph, considering $v_1$ and $v_4$ as a combined \"supernode\"." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "F = \n", "print('\\nF:\\n',F)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(ii) Specify the resistance matrix R and the vector of voltage sources $\\vec{b}$." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "R = \n", "\n", "b = \n", "\n", "# For convenience, we will define the conductance matrix G as the inverse of R.\n", "G = np.linalg.inv(R)\n", "\n", "print('\\nR:\\n',R)\n", "print('\\nb:\\n',b)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(iii) Write down the vector f so that KCL is satisfied as: $F^T i + f = 0$" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "f = \n", "print('\\nf:\\n', f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(iii) What is the rank of F? Does it have a null space? If so, what is it?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Edit your answer to (iii) here." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# any code you write to help you answer above\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(iv) Setting a potential in v to 0 corresponds to deleting a column of F. Let $v_4 = 0$, and write down our new \"grounded\" matrix F: F_grounded" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "F_grounded = \n", "print('\\nF_grounded:\\n', F_grounded)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(v) Implement your algebraic solution to compute v in terms of F, G, $\\vec{f}$, and $\\vec{b}$. You may also have to slice $\\vec{f}$ and $\\vec{b}$." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [], "source": [ "A = \n", "print('\\nA:\\n', A)\n", "\n", "B = \n", "print('\\nB:\\n', B)\n", "\n", "v = \n", "print('\\nv:\\n', v)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(vi) Compute $\\vec{i}$ with your solution of $\\vec{v}$." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "i = \n", "\n", "print('\\ni:\\n', i)" ] } ], "metadata": { "anaconda-cloud": {}, "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.5" } }, "nbformat": 4, "nbformat_minor": 0 }