SymMNA is a Python module that will generate a system of equations from a circuit’s netlist using Modified Nodal Analysis (MNA).
Consider the schematic of the circuit shown below. This circuit has nine branches and five nodes. There are four resistors, two independent voltage sources and one independent current source. Additionally there is one VCCS and one CCVS. Each of the nodes is labeled along with the ground node.
The circuit was drawn with LTSpice and the netlist can be copied and pasted into the code snippet below.
net_list = ''' R1 1 4 2 R2 1 2 1 R3 4 3 1 R4 2 5 2 V1 1 0 2 I1 4 0 9 H1 2 3 V2 3 G1 0 3 1 4 2 V2 0 5 0 ''' # generate the network equations from the netlist report, network_df, i_unk_df, A, X, Z = SymMNA.smna(net_list) # Put matrices into SymPy X = Matrix(X) Z = Matrix(Z) # formulate the equations NE_sym = Eq(A*X,Z) # generate markdown to display the equations temp = '' for i in range(len(X)): temp += '${:s}$<br>'.format(latex(Eq((A*X)[i:i+1][0],Z[i]))) Markdown(temp) The following equations were automatically generated.
From here, SymPy, NumPy and SciPy are used to solve the equations and perform additional calculations.
Additional examples and documentation can be found here:
- Symbolic Modified Nodal Analysis using Python for an HTML book.
- SymMNA_demo.ipynb for a JupyterLab example.
This work (includes python code, documentation, test circuits, etc.) is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
- Share — Copy and redistribute the material in any medium or format.
- Adapt — Remix, transform, and build upon the material for any purpose, even commercially.
- Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.

