Skip to content
Luca Giaccone edited this page Aug 4, 2017 · 13 revisions

Welcome to the SpicePy wiki!

Basic example

Let us consider the network in the following figure,

it is described by the file network.net including the following lines:

R2 1 2 5
R1 1 3 10
V2 2 0 15
V1 3 0 5
I1 2 1 2
R3 1 0 2

(Elements are intentionally included without a fixed order.)

The network can be solved executing the following python script:

# import modules
import netlist as ntl
from netsolve import dc_solve
import netpost as pst
import netprint as prn

net = ntl.Network('network.net')    # load network from netlist
x = dc_solve(net)                   # solution
vb = pst.branch_voltage(net)        # compute branch voltages
ib = pst.branch_current(net)        # compute branch currents

prn.print_branch_quantity(net)      # print results

On the terminal/shell the following result is obtained:

==============================================
               branch quantities              
==============================================
v(R1) =     1.8750 V    i(R1) =     0.1875 A
v(R2) =    -8.1250 V    i(R2) =    -1.6250 A
v(R3) =     6.8750 V    i(R3) =     3.4375 A
v(V1) =     5.0000 V    i(V1) =     0.1875 A
v(V2) =    15.0000 V    i(V2) =    -3.6250 A
v(I1) =     8.1250 V    i(I1) =     2.0000 A
==============================================

(Please note that the output is reordered: resistors, voltage sources and then current sources.)