# Networks¶

Lcapy supports one-port and two-port networks.

## One-port networks¶

One-port networks are creating by combining one-port components in series or parallel, for example, here’s an example of resistors in series

>>> from lcapy import R
>>> R1 = R(10)
>>> R2 = R(5)
>>> Rtot = R1 + R2
>>> Rtot
R(10) + R(5)


Here R(10) creates a 10 ohm resistor and this is assigned to the variable R1. Similarly, R(5) creates a 5 ohm resistor and this is assigned to the variable R2. Rtot is the name of the network formed by connecting R1 and R2 in series.

>>> Rtot.draw()


### Network attributes¶

Each network has a number of attributes, including:

• Voc s-domain open-circuit voltage
• Isc s-domain short-circuit current
• I s-domain current through network terminals (zero by definition)
• Z s-domain impedance
• voc t-domain open-circuit voltage
• isc t-domain short-circuit current
• isc t-domain current through network terminals (zero by definition)
• y t-domain impulse response of admittance
• z t-domain impulse response of impedance
• is_dc DC network
• is_ac AC network
• is_ivp initial value problem
• is_causal causal response

Here’s an example:

>>> from lcapy import R, V
>>> n = V(20) + R(10)
>>> n.Voc
20
──
s
>>> n.voc
20
>>> n.Isc
2
─
s
>>> n.isc
2
>>> n.Z
10
>>> n.Y
1/10


### Network simplification¶

A network can be simplified (if possible) using the simplify method. For example, here’s an example of a parallel combination of resistors. Note that the parallel operator is | instead of the usual ||.

>>> from lcapy import *
>>> Rtot = R(10) | R(5)
>>> Rtot
R(10) | R(5)
>>> Rtot.simplify()
R(10/3)


The result can be performed symbolically, for example,

>>> from lcapy import *
>>> Rtot = R('R_1') | R('R_2')
>>> Rtot
R(R_1) | R(R_2)
>>> Rtot.simplify()
R(R_1*R_2/(R_1 + R_2))
>>> Rtot.simplify()
R(R₁) | R(R₂)


Here’s another example using inductors in series

>>> from lcapy import *
>>> L1 = L(10)
>>> L2 = L(5)
>>> Ltot = L1 + L2
>>> Ltot
L(10) + L(5)
>>> Ltot.simplify()
L(15)


Finally, here’s an example of a parallel combination of capacitors

>>> from lcapy import *
>>> Ctot = C(10) | C(5)
>>> Ctot
C(10) | C(5)
>>> Ctot.simplify()
C(15)


### Norton and Thevenin transformations¶

A Norton or Thevenin equivalent network can be created using the norton or thevenin methods. For example,

>>> from lcapy import Vdc, R
>>> a = Vdc(1) + R(2)
>>> a.norton()
G(1/2) | Idc(1/2)


## Network schematics¶

One port networks can be drawn with a horizontal layout. Here’s an example:

>>> from lcapy import R, C, L
>>> ((R(1) + L(2)) | C(3)).draw()


Here’s the result:

The s-domain model can be drawn using:

>>> from lcapy import R, C, L
>>> ((R(1) + L(2)) | C(3)).smodel().draw()


This produces:

Internally, Lcapy converts the network to a netlist and then draws the netlist. The netlist can be found using the netlist method, for example,

>>> from lcapy import R, C, L
>>> print(((R(1) + L(2)) | C(3)).netlist())


yields:

W 1 3; right, size=0.5
W 3 4; up, size=0.4
W 3 5; down, size=0.4
W 6 2; right, size=0.5
W 6 7; up, size=0.4
W 6 8; down, size=0.4
R 4 9 1; right
W 9 10; right, size=0.5
L 10 7 2 0; right
C 5 8 3 0; right


Note, the components have anonymous identifiers.

To create a schematic with multiple components in parallel, use Par. For example,

from lcapy import R, C, L, Par
N = Par(R(1), R(2), R(3))
N.draw('par3.png')


## Network analysis examples¶

### Series R-C network¶

from lcapy import *
from numpy import logspace
from matplotlib.pyplot import figure, savefig

N = R(10) + C(1e-4)

vf = logspace(0, 5, 400)
Z = N.Z(f).evaluate(vf)

fig = figure()
ax.loglog(vf, abs(Z), linewidth=2)
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Impedance (ohms)')
ax.grid(True)

savefig('series-RC1-Z.png')

from lcapy import *
from numpy import linspace
from matplotlib.pyplot import savefig

N = Vstep(20) + R(10) + C(1e-4, 0)

vt = linspace(0, 0.01, 1000)
N.Isc(t).plot(vt)

savefig('series-VRC1-isc.png')


### Series R-L network¶

from lcapy import *
from numpy import logspace
from matplotlib.pyplot import figure, savefig

N = R(10) + L(1e-2)

vf = logspace(0, 5, 400)
Z = N.Z(f).evaluate(vf)

fig = figure()
ax.loglog(vf, abs(Z), linewidth=2)
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Impedance (ohms)')
ax.grid(True)

savefig('series-RL1-Z.png')


from lcapy import *
from numpy import linspace
from matplotlib.pyplot import savefig

N = Vstep(20) + R(10) + L(1e-2, 0)

vt = linspace(0, 0.01, 1000)
N.Isc(t).plot(vt)

savefig('series-VRL1-isc.png')


### Series R-L-C network¶

from lcapy import *
from numpy import logspace
from matplotlib.pyplot import savefig

N = R(10) + C(1e-4) + L(1e-3)

vf = logspace(0, 5, 400)
N.Z(f).magnitude.plot(vf)

savefig('series-RLC3-Z.png')

from lcapy import Vstep, R, L, C, t
from matplotlib.pyplot import savefig
from numpy import linspace

a = Vstep(10) + R(0.1) + C(0.4) + L(0.2, 0)

vt = linspace(0, 10, 1000)
a.Isc(t).plot(vt)

savefig('series-VRLC1-isc.png')


### Parallel R-L-C network¶

from lcapy import *
from numpy import logspace
from matplotlib.pyplot import figure, savefig

N = R(10) | C(1e-4) | L(1e-3)

vf = logspace(0, 5, 400)
Z = N.Z(f).evaluate(vf)

fig = figure()
ax.loglog(vf, abs(Z), linewidth=2)
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Impedance (ohms)')
ax.grid(True)

savefig('parallel-RLC3-Z.png')

from lcapy import Istep, R, L, C, t
from matplotlib.pyplot import figure, savefig
import numpy as np

a = Istep(10) | R(0.1) | C(0.4) | L(0.2)

a.Voc.pprint()

vt = np.linspace(0, 10, 1000)

fig = figure()