In the following, we will use a python package SchemDraw to help us make electric circuit diagrams and symbols. Please install SchemDraw first if you want to correctly run these codes.
pip install SchemDraw
See here.
#Run these headers first (ctrl+enter)
import matplotlib.pyplot as plt
import SchemDraw
import SchemDraw.elements as elm
#SchemDraw uses matplotlib inline mode (if you want to see the output, uncomment the next line.)
# %matplotlib inline
#Generate vector image format for better resolution
%config InlineBackend.figure_format = 'svg'
# Start drawing by creating a drawing object
# d = SchemDraw.Drawing()
# For more details, see the following examples or the document
#Create a resistor symbol
d = SchemDraw.Drawing()
d.add(elm.RES,label='resistor')
d.draw()
d.save('ch05_res_sym.svg')
#Create a symbol for series-connected resistors
d = SchemDraw.Drawing()
d.add(elm.RES,label='$R_1$')
d.add(elm.RES,label='$R_2$')
d.draw()
d.save('ch05_sres_sym.svg')
#Create a symbol for parallel-connected resistors
d = SchemDraw.Drawing()
d.add(elm.LINE,l=3)
d.add(elm.RES,d='up',label='$R_1$')
d.add(elm.LINE,d='left',l=2)
d.push()
d.add(elm.RES,d='down',label='$R_2$')
d.pop()
d.add(elm.LINE,d='left',l=1)
d.draw()
d.save('ch05_pres_sym.svg')
#Create a battery symbol
d = SchemDraw.Drawing()
d.add(elm.BAT_CELL, label=['+ ','$V_{emf}$',' $-$'])
d.draw()
d.save('ch05_bat_sym.svg')
#Create a battery symbol
d = SchemDraw.Drawing()
d.add(elm.SOURCE_V, label='$V_{emf}$')
d.draw()
d.save('ch05_sourcev_sym.svg')
#Create a capacitor symbol
d = SchemDraw.Drawing()
d.add(elm.CAP,label='capacitor')
d.draw()
d.save('ch05_cap_sym.svg')
#Create an RC series circuit symbol
d = SchemDraw.Drawing()
d.add(elm.SOURCE_V,d='up',label='$V_{emf}$')
C1=d.add(elm.CAP,d='right',label='C',l=5,reverse=True)
d.labelI_inline(C1,'$I$',d='in',start=True)
d.add(elm.RES,d='down',label='R')
d.add(elm.SWITCH_SPST,d='left',label='S',l=5)
d.draw()
d.save('ch05_s_rc_sym.svg')
#Create an RC parallel circuit symbol
d = SchemDraw.Drawing()
d.add(elm.SOURCE_V,d='up',label='$V_{emf}$')
d.add(elm.RES,d='right',l=3,label='$R_1$')
d.push()
d.add(elm.CAP,d='down',label='C')
d.pop()
d.add(elm.LINE,d='right',l=2)
d.add(elm.RES,d='down',label='$R_2$')
d.add(elm.LINE,d='left',l=2)
d.add(elm.SWITCH_SPST,label='S')
d.draw()
d.save('ch05_p_rc_sym.svg')
#Create a resistor network circuit
d = SchemDraw.Drawing()
d.add(elm.SOURCE_V,d='up',label='$5V$')
d.add(elm.DOT,label='$V_1$')
R1=d.add(elm.RES,d='right',botlabel='2$\Omega$')
d.add(elm.DOT,label='$V_2$')
d.push()
R2=d.add(elm.RES,d='down',label='3$\Omega$')
d.pop()
d.add(elm.LINE,d='right',l=2)
d.add(elm.RES,d='down',label='5$\Omega$')
d.add(elm.LINE,d='left',l=2)
d.add(elm.DOT,botlabel='$V_3=0$')
d.add(elm.LINE,d='left',l=3)
d.draw()
d.save('ch05_rnetwork_sym.svg')
Current is defined as an amount of charge passing through a specific cross-section within a unit time: \begin{equation} I=\frac{\Delta Q}{\Delta t} \end{equation}
In conductors, current is produced by moving charges pushed by electric field (it is not electrostatic anymore).
For a moving charged particle, note that the current does not depend on the speed. But for many charge particles, the current (flux) is given by the charge density multipled by speed. (See next section.)
In electrostatic equilibrium, the field inside a conductor is zero. But here, when the conductor is applied two voltages, which generate an electric field constantly, free charges can move along the field lines, and form a current.
If there is no way to conduct the current to the ground (large capacitor like earth) or form a loop, charges must accumulate and start to form an opposing field to the applied field until the net field is cancelled $E=0$. Then the electrostatic equilibrium is restored.
If there is a loop, somewhere in the loop must be a source of electromotive force (emf), which creates voltage rise for positive charges flowing in from one end to the other end.
Unit of current: A (Ampere)= C/sec. (2018) Definition from the force between two parallel wires carrying current is obsolete.
In conductors, charges move due to the push by the electric field. But will they have different average speed along a conductor? Answer is no!! Why?
Charge carriers move and collide with the hard cores fixed in the space. The speed (balancing the accelration and collision) is called the drift velocity.
The drift velocity is typically $\sim 10^{-4}$ m/s.
Consider a current $I$ in a copper wire of cross-section $A$. Suppose the charge density is $n$ (number of free electrons per unit volume) and the electron's drift velocity is $v_d$: \begin{equation} I=env_dA. \end{equation}
Consider a cylindrical conducting wire whose two terminals are applied a voltage diffrence $V$. In linear devices $v_d\propto V$ (You may think $v_d$ as the terminal velocity). So we can measure the conductivity of the conductor by looking at $R=\frac{V}{I}$, called the resistance. (There is also a quantity called conductance defined as I/V).
R=V/I is called Ohm's law. Any device that obeys Ohm's law is called ohmic.
Unit: 1 $\Omega$ (Ohm)= V/A.
A device of length L and of uniform cross-section $A$ has a resistance \begin{equation} R=\rho\frac{L}{A} \end{equation} where $\rho$ is called resistivity of the material. $\rho$ has a unit $\Omega\cdot$ m.
$\rho$ can change with temperature: \begin{equation} \rho(T)=\rho(T_0) [1+\alpha(T-T_0)] \end{equation} is approximately correct within certain temperature range. $\alpha$ is called the temperature coefficient of resistivity, and is also a property associated with the material.
Symbol of a resistor in a circuit:
Series combination of resistors: $R_{eff}=\sum_i R_i$. Why?
Parallel combination of resistor: $R_{eff}^{-1}=\sum_i R_i^{-1}$. Why?
A device that maintains a constant voltage in a circuit
Examples: batteries, generators (will be discussed in Chapter 7 Induction).
Batteries were first invented in 1799 by Alessandro Volta (Italy), based on eletrochemical reaction between Copper (cathode) and Zinc (anode) separated by cloth or cardboard soaked in brine (eletrolyte). Each cell (zic/eletrolyte/copper) can generate 0.76 V.
The reaction taking place at the anode is called oxidation: Zn$\rightarrow$Zn$^{2+}$+2e$^-$.
The reaction taking place at the cathode is called reduction: 2H$^+$+2e$^-\rightarrow$H$_2$.
Notation: $\mathcal E$ or $V_{emf}$.
Unit: V (Volt)
A real baterry can be thought to have both emf $\mathcal E$ and (internal) resistance $r$. The actual terminal voltage depends on current: $V=\mathcal E-Ir$. In fact, a dead battery just means the internal resistance becomes too large to provide the terminal voltage.
Circuit symbol:
A charge $q$ passing by a voltage drop $V$ gains an energy $qV$. Suppose the time elapsed is $t$. The power is $P=qV/t=IV$.
In a circuit, a current $I$ passing through a device that causes a voltage drop $V$ does a power $IV$.
Similarly, in a circuit, an emf takes charges from the low-voltage end to the high-voltage end (with a voltage rise $\mathcal E$) so that the current can do work. It is equivalent to say the emf provides a power to the circuit $P=I\mathcal E$.
A resistor $R$ dissipates the electrical power to heat via $P=IV=I^2 R=V^2/R$, where $V$ is the voltage drop and $I$ is the current passing through it.
Due to energy conservation, in a circuit, the power input provided by emfs must be equal to power dissipated by resistors plus the energy stored in (or minus the erergy released from) capacitors and/or inductors: \begin{equation} \Delta P_{\mathcal E}=\Delta P_{R}+\Delta P_{C/I} \end{equation} where $\Delta P_{C/I}>0$ means some energy is being stored into the capacitor/inductor, and $\Delta P_{C/I}<0$ means some energy is being released from the capacitor/inductor.
A circuit is a network consisting of emfs and electrical devices. Mathematically, a network is formed by nodes and edges. Here, since all directly connected conductors share the same potential, so they contribite to the same node of a specific voltage. Any electrical device sits on an edge with their ends connecting to two different nodes.
Passive circuits: The power input and disspation is self-sustained in a network without extrenal electric sources, which are usually used to drive active devices like amplifiers and nonlinear filters.
Circuit diagrams: drawing and analysis. See Kirchhoff's rules.
The sum of currents flowing out of a node (via connecting edges) is 0. For node $i$: \begin{equation} \sum_j I_{i\rightarrow j}=0 \end{equation}
The sum of the voltage changes between edges following any loop chosen from a circuit is 0. \begin{equation} \sum_{\{i\rightarrow j\} \in C} \Delta V_{ij}=0. \end{equation}
A capacitor does not dissipate energy (but it can store energy).
The circuit symbol for a capacitor
By forcing a charge $dq$ to be stored in a capacitor while its voltage is $V$, the needed work is $Vdq$. (Recall the energy stored in a capacitor is $E=\frac{1}{2}QV$. Why?) So, the power $Vdq/dt=IV$, consistant with previous discussions.
Note that $C=Q/V$, the capacitance is basically the stored charge per unit voltage, and is usually a constant (depending only on the geometrical factor and dielectric properties) so $dq=CdV$. Divide both sides by $dt$, and then we get the current-voltage (I-V) relation: \begin{equation} I=C\frac{dV}{dt} \end{equation}
The I-V relation is one of the most important information for circuit design and device engineering. Here we have learned two examples: $V=IR$ and $I=CdV/dt$.
Simplest example of an RC circuit: A series combination of a resistor $R$, a capacitor $C$, an emf $\mathcal E$, and a switch $S$. The circuit is switched on when the switch is closed (connected, closed-circuit, or short-circuit), and switched off when the switch is open (cut, or open circuit). Suppose initially $t<0$, there is no current.
Question: Find the current and voltage across the capacitor, and the associated charges
Analysis:
At $t=0$ the switch is closed (turned on). The terminal voltage across the capacitor $V_C=Q(t=0)/C=0$, meaning that it is effectively a short circuit across the capacitor.
When $t\rightarrow\infty$, the capacitor is fully charged, the current stops flowing and it is equivalent to an open circuit.
Note that in general this is a charging process so the current I(t), voltage V(t), and charge Q(t) on the capacitor are all functions of time.
Since there is only one loop, Kirchhoff's juction rule implies that the current $I(t)$ is all the same along the loop.
For analysis, it is always helpful to assume the current direction. If the computed value is positive, then the assumed direction is correct. If negative, the current flows reversely. Now, suppose the current is flowing out from the positive end of the emf, through the circuit loop, and return to the emf's negative end.
For analysis, it is always helpful to assume the voltage difference across the capacitor to be $V_C=V_{in}-V_{out}$, where $V_{in}$ is associated with the node where the assumed current flows into the capacitor, and $V_{out}$ associated with the node where the assumed current flows out of the capacitor. $V_C$ obeys \begin{equation} I=C\frac{dV_C}{dt}. \end{equation}
Apply Kirchhoff's loop rule: \begin{equation} \mathcal E=V_R+V_C=IR+V_C=RC\frac{dV_C}{dt}+V_C. \end{equation} We solve for $V_C$ and get \begin{equation} V_C(t)=\mathcal E(1-e^{-t/\tau}) \end{equation} where $\tau=RC$ is called characteristic time constant of the circuit.
Similarly, \begin{eqnarray} I(t)&=&\frac{\mathcal E-V_C(t)}{R}=\frac{\mathcal E}{R}e^{-t/\tau}\\ Q(t)&=&C V_C(t)=C\mathcal E(1-e^{-t/\tau}). \end{eqnarray}
Discharging
Parallel circuits
When the electric circuit becomes very complicated, how can we make good use of computer programs that help solve the problems? Here we are goig to learn a method based on linear algebra for linear electric network. Since RC circuits involve solving differential equations, here we simplify our discussion to look at resistor only circuits with arbitrary emfs.
Following is the approach:
Consider the example: \begin{eqnarray} x+y+z&=&8\\ 2x+3y-z&=&2\\ 3x-y-2z&=&-5 \end{eqnarray} which can be recast into the matrix form \begin{equation} \underbrace{\left(\begin{array}{ccc} 1 & 1 & 1\\ 2 & 3 & -1\\ 3 & -1 & -2 \end{array}\right)}_A \underbrace{\left(\begin{array}{c} x\\ y\\ z \end{array}\right)}_X =\underbrace{\left(\begin{array}{c} 8\\ 2\\ -5 \end{array}\right)}_b \end{equation} Then $X=A^{-1}b$. (Numpy has provided a package that can invert a matrix.)
Consider a circuit consisting of $N$ nodes,each of which corresponds to a voltage $V_i$. Some of these nodes are connected by edges with resistors and batteries.
Analysis:
Assume every node has a voltage $V_i$. But one of them can be set to 0 as the reference (ground).
If any pair of them are connected via a resistor $R_{ij}$ (given), then the current passing through the resistor is not an independent variable because $I_{ij}=(V_i-V_j)/R_{ij}$.
Suppose we have $M$ batteries, each of which connects two nodes: $\mathcal E_{ij}=V_i-V_j$. But the current passing through a battery is to be determined.
We thus have $N-1$ unknown voltages and $M$ unknown currents, so $N-1+M$ independent variables.
To solve for them, we need $N-1+M$ equations. But we already have $M$ battery conditions $\mathcal E_{ij}=V_i-V_j$. We still need $N-1$ more.
We can apply Kirchhoff's junction rule on each node: \begin{equation} \sum_{j\in R_i} \frac{V_i-V_j}{R_{ij}}+\sum_{j \in B_i}I_{ij}=0 \end{equation} where $R_i$ means the subset of node $i$'s neighbors connected with resistors, and $B_i$ means the subset of node $i$'s neighbors connected with batteries. We have $N$ nodes, then we have $N$ equations
$N$ equations is one too many than what we need. In fact, these $N$ equations are not independent. When we sum all these equations, we get $0=0$. There are only $N-1$ independent equations in the, so we can throw any one equation away.
Construct the matrix euqation. Solve for the unknown voltages and currents.
Consider the circuit
Write down the equations \begin{eqnarray} V_1-0&=&5\\ \frac{V_1-V_2}{2}+I_{13}&=&0\\ \frac{V_2-V_1}{2}+\frac{V_2-0}{3}+\frac{V_2-0}{5}&=&0 \end{eqnarray} and recast into the matrix form \begin{equation} \left(\begin{array}{ccc} 1 & 0 & 0\\ \frac{1}{2} & -\frac{1}{2} & 1\\ -\frac{1}{2} & \frac{1}{2}+\frac{1}{3}+\frac{1}{5} & 0 \end{array}\right) \left(\begin{array}{c} V_1\\ V_2\\ I_{13} \end{array}\right) =\left(\begin{array}{c} 5\\ 0\\ 0 \end{array}\right) \end{equation} Here we have thrown out the junction equation associated with node 3.
This circuit can be solved by the following codes, which can be generalized to any resistor network circuit:
import numpy as np
import numpy.matlib as mat
#You can actually encode the whole circuit into a table
CIRCUIT=[[1,3,5,True],[1,2,2,False],[2,3,3,False],[2,3,5,False]]
#Format: [node i,node j, value,is_a_battery]
#For example: [1,3,5,True] means an edge connecting node 1 and node 3.
# Across the edge is a battery of 5V (=V1-V3).
#Another example: [1,2,2,False] means an edge connecting node 1 and node 2.
# Across the edge is a resistor of 2 ohms
# Extract circuit information: N nodes, listRES as list of resistors, listBAT as list of batteries
N=0
listBAT=[]
listRES=[]
for ii in np.arange(len(CIRCUIT)):
if N<max(CIRCUIT[ii][0:2]):
N=max(CIRCUIT[ii][0:2])
if CIRCUIT[ii][3]==True:
listBAT.append(CIRCUIT[ii][0:3])
else:
listRES.append(CIRCUIT[ii][0:3])
M=len(listBAT)
# Construct cofficient matrix A and input vector b
A=mat.zeros((N-1+M,N-1+M))
b=mat.zeros((N-1+M,1))
for ii in np.arange(M):
if listBAT[ii][0]!=N:
A[ii,listBAT[ii][0]-1]=1.
A[M+listBAT[ii][0]-1,N-1+ii]=1.
if listBAT[ii][1]!=N:
A[ii,listBAT[ii][1]-1]=-1.
A[M+listBAT[ii][1]-1,N-1+ii]=-1.
b[ii,0]=listBAT[ii][2]
for ii in np.arange(len(listRES)):
if listRES[ii][0]!=N:
A[M+listRES[ii][0]-1,listRES[ii][0]-1]=A[M+listRES[ii][0]-1,listRES[ii][0]-1]+1./listRES[ii][2]
if listRES[ii][1]!=N:
A[M+listRES[ii][1]-1,listRES[ii][0]-1]=A[M+listRES[ii][1]-1,listRES[ii][0]-1]-1./listRES[ii][2]
if listRES[ii][1]!=N:
A[M+listRES[ii][1]-1,listRES[ii][1]-1]=A[M+listRES[ii][1]-1,listRES[ii][1]-1]+1./listRES[ii][2]
if listRES[ii][0]!=N:
A[M+listRES[ii][0]-1,listRES[ii][1]-1]=A[M+listRES[ii][0]-1,listRES[ii][1]-1]-1./listRES[ii][2]
print('Here we set the voltage of the largest index is 0.')
#Here is the code that solves the circuit matrix
#A=np.matrix([[1,0,0],[1/2,-1/2,1],[-1/2,1/2+1/3+1/5,0]])
#b=np.matrix([[5],[0],[0]])
X=np.linalg.inv(A)*b #Calculate the inverse of A
print(X)
So we get
$V_1=5$ V
$V_2=2.42$ V
$I_{13}=-1.29$ A, meaning the actual current flowing from node 3 to node 1 through the battery.
# You can also insert these codes to read a table that represents a circuit network
import csv
from distutils.util import strtobool
with open('test.txt') as f:
myCsv = csv.reader(f)
# headers = next(myCsv)
CIRCUIT=[]
for row in myCsv:
trow = list(map(int, row[0:3]))
trow.append(strtobool(row[3]))
CIRCUIT.append(trow)