1  Introduction

The purpose of this book is to describe a method implemented in the Python programming language that will automatically generate symbolic network equations from a circuit’s netlist. The Python programming language and the associated libraries such as SymPy and NumPy make analyzing electric circuits almost effortless and the JupyterLab Notebooks described in this book can be used as template for analyzing almost any linear electric circuit.

This book is not a college text book about circuit analysis, there are many good books available that cover this topic. This book is about using Modified Nodal Analysis and the Python programming language to analyze electric circuits. Python’s open-source nature makes it a powerful and cost-effective tool for complex computational problems.

Circuit analysis is a foundational skill necessary for a broad range of professionals whose work involves the design and development of electronic systems. Electrical Engineers and Circuit Designers are the core audience, as they rely on techniques like Kirchhoff’s Laws to create efficient circuits, calculate voltage drops and current flows, and simulate how an electric circuit will behave before it’s ever built. Fields like Power Systems Engineering, Control Systems Engineering and even Physics require this knowledge to understand energy distribution, optimize system performance and analyze complex physical models where circuits are used as analogues.

The Modified Nodal Analysis (MNA) is an essential extension of standard Nodal Analysis, and its primary benefits revolve around its systematic and comprehensive nature, particularly for computer-aided analysis. The key advantage of MNA is its ability to accommodate many types of circuit elements in a single, unified matrix formulation. Unlike traditional Nodal Analysis, which struggles to directly model voltage sources and components whose current is not easily defined by node voltages (such as dependent voltage sources and inductors), MNA introduces the currents through these elements as additional unknown variables. This standardization makes the process of formulating the circuit equations highly algorithmic and straightforward to automate, forming the backbone of professional circuit simulators like SPICE. Consequently, MNA eliminates the need for manual, ad-hoc techniques like supernodes or source transformations, allowing for the rapid and reliable analysis of large, complex, and linear circuits.

1.1 What Is Circuit Analysis and Who Is This Book For?

Electric circuit analysis is the process of figuring out the unknown currents and voltages in a network of connected electrical components, which is commonly call a circuit. It is a fundamental skill that is taught to engineering students and serves as the bedrock for understanding and designing virtually all modern electrical and electronic systems.

Circuit analysis is used for calculating power flow, voltage drops and fault currents in power grids; designing amplifiers, filters, power supplies and logic circuits for devices like smartphones and computers. This process relies on using basic physical laws and systematic mathematical techniques to create and solve a system of independent equations.

This method presented in this book will be particularly useful when the circuit is of simple to moderate complexity and symbolic network equations are desired. In some cases, symbolic solutions for the equations can be obtained.

1.2 Who Is This Book Not For?

There are a few cases where MNA and the Python code presented in this book may not be that useful for you.

  • This book or the JupyterLab notebooks may not be particularly useful for students doing circuit analysis homework assignments by hand with pencil and paper. If the student is asked to find the loop equations or traditional node equations, the automatically generated MNA equations will be different.
  • The input to the Python code is a netlist and generating the netlist either by hand or with a schematic capture program may be more work than just determining the network equations in the traditional way.
  • If the circuit is so simple that the unknown variables can be solve for almost by inspection, starting with a netlist is not necessary and requires unnecessary additional work.

1.3 Assumptions

A basic understanding of Python programming is helpful, meaning you should be familiar with core concepts such as variables, data types (e.g., lists, dictionaries and strings), control flow (using if else statements and for while loops) and defining and calling functions.

Additionally, familiarity with JupyterLab notebooks is required. This involves knowing how to navigate the interface, create new notebooks, write and run code within cells, and utilize Markdown cells for documentation and annotation. JupyterLab serves as the primary interactive environment for writing and testing Python code.

The analysis of electric circuits, whether done by hand or with the help of Python and MNA, fundamentally relies on the concept of ideal components. These are theoretical abstractions that possess perfect behavior (e.g., a resistor has only resistance, an inductor has only inductance) and ignore the inevitable imperfections of real-world devices, such as parasitic capacitance, lead resistance, or temperature dependence.

Furthermore, almost all conventional circuit analysis methods, including Nodal and Mesh analysis, rely on the assumption of a lumped-element model, which assumes the circuit is small enough that electrical effects occur instantaneously throughout the circuit, neglecting the time delay associated with the propagation of electromagnetic fields. This allows us to treat the circuit’s current and voltage as functions of time alone, rather than of both position and time (as required for wave propagation or transmission line effects). Finally, the systematic matrix methods discussed (MNA) are designed specifically for linear time-invariant (LTI) circuits, where the relationship between voltage and current is linear (e.g., Ohm’s law holds true) and the component values or connections do not change over time.

1.4 Why Not Just Use SPICE or Some Other Program?

The core reason you need symbolic analysis even with powerful numerical tools like SPICE is the difference between a number and a formula. SPICE and similar programs are numerical simulators. They give you a specific number for a specific set of component values and inputs.

Symbolic analysis, however, gives you the actual algebraic formulas for the circuit’s behavior. While powerful, exact symbolic analysis is typically limited to smaller circuits because the complexity and length of the resulting expressions grow dramatically with the number of components and branches in the network.

The Python code presented in this notebook is somewhat unique since Python is open source, free and runs on a variety of platforms, the code presented in the JupyterLab notebooks is portable. As described in the Welcome page, the Python code is made available under a public domain license and archived in a GitHub repository, see Section 1.

There are other symbolic circuit analysis codes available and some of these are described here. Some of these codes are based on commercial software such as MATLAB, TINA and Maple.

SLiCAP is a symbolic linear analysis tool. SLiCAP is now a Python program, but originally it was written in MATLAB.

TINA is an acronym of Toolkit for Interactive Network Analysis. The TINA design suite is a circuit simulator and PCB design software package for analyzing, designing, and real time testing of analog, digital, HDL, MCU, and mixed electronic circuits and their PCB layouts. TINA has some symbolic analysis capability.

Maple is a mathematical package and there is an application note available describing its use in symbolic circuit analysis. The application note presents a method for evaluating, solving and designing a common, but not so simple pulse-mode high-gain transimpedance amplifier or TIA circuit.

Symbolic Circuit Analysis is a web page devoted to symbolic circuit analysis.

SAPWIN is a windows program package for symbolic and numerical simulation of analog circuits.

Lcapy is an experimental Python package for teaching linear circuit analysis. It uses SymPy for symbolic mathematics. Hayes (2022) provides an overview of Lcapy as well as a survey of symbolic circuit analysis packages.

LTSpice has been used extensively to verify the MNA numerical results in addition to drawing the circuit schematics shown in this book’s examples.

1.5 Why Use Symbolic Circuit Analysis?

Symbolic circuit analysis is a formal technique where the behavior or characteristic of a circuit (like voltage gain or impedance) is calculated with the circuit components and frequency (or time) represented by symbols instead of numerical values.

For small circuits, the analytical expression (e.g., a transfer function) explicitly shows how each component affects the circuit’s performance metrics (gain, poles, zeros, etc.). This allows a designer to immediately see which elements are dominant and how to modify component values to meet specifications. A symbolic expression remains valid across a range of component values and operating conditions (as long as the underlying model is valid). By using symbolic analysis the network equations in symbolic form can be useful to document a design or to include in a technical paper.

1.6 Getting Started

The best way to begin your journey into symbolic circuit analysis with Python is through hands-on practice. The most effective approach is to copy one of the provided JupyterLab Notebooks and use it as a template for analyzing your own circuits. By doing this, you’ll immediately begin applying the Modified Nodal Analysis (MNA) method and leverage the computational power of Python libraries like SymPy for symbolic computation, NumPy for numerical handling, and Matplotlib for generating plots.

This practical, project-oriented approach will quickly familiarize you with setting up a circuit’s netlist, deriving its symbolic network equations, solving for unknown voltages and currents, and gaining the deep, qualitative insights that only symbolic analysis can provide.

Source code for this book is available here and related material is located here. Python code contained in this book can run in a browser-based environment, see Appendix C. Additionally, online schematics editors are available, see Appendix E. By using web based tools, the reader is not required to install any programs.

Rewrite this section and point to Section 1 to keep Github links all in one place.

1.7 About the Math

The type of math used in circuit analysis depends on the complexity and nature of the circuit. Solving calculus and differential equations are not used in the analysis presented in this book. Since the Python modules SymPy and NumPy are being extensively employed, actual proficiency with the math is not really required. However, there are some advance concepts that are used throughout the book and that are not really explained.

  • Complex Numbers: Crucial for AC circuit analysis, where quantities like impedance are represented as complex numbers to simplify calculations involving magnitude and phase shifts in sinusoidal waveforms. The Laplace Transform is used to convert differential equations into algebraic equations.
  • Linear Algebra: Essential for solving systems of simultaneous linear equations that result from MNA.

1.8 Summary

This book serves as a practical guide for performing symbolic circuit analysis using the Python programming language and its associated scientific libraries, such as SymPy and NumPy. The primary goal is to provide a systematic and computationally efficient method for analyzing linear electric circuits, utilizing JupyterLab Notebooks as adaptable templates.

The book is not a traditional circuit analysis textbook but focuses specifically on implementing the Modified Nodal Analysis (MNA) method. MNA is an essential extension of standard nodal analysis that allows all types of circuit elements (including voltage sources, inductors, and dependent sources) to be incorporated into a single, unified matrix formulation. This approach forms the algorithmic backbone of professional circuit simulators like SPICE.

Important Points:

  • Symbolic Analysis: This technique calculates a circuit’s behavior (e.g., gain, impedance) with components and frequency represented by symbols instead of numerical values. This provides qualitative insight into the circuit’s operation, aids in design optimization, and yields exact analytical solutions that numerical simulators (like SPICE) cannot.
  • Target Audience: Circuit analysis is a foundational skill for a broad range of professionals, including Electrical Engineers, Circuit Designers, Electronics Technicians and those in Power Systems and Control Systems Engineering.
  • Modified Nodal Analysis (MNA): The book leverages MNA to formulate the circuit problem as a system of simultaneous linear equations, \(\mathbf{G} \cdot \mathbf{V} = \mathbf{I}\), which are then solved using matrix inversion implemented in Python.
  • Advanced Concepts (The s-Domain): The text covers Laplace Transformed Circuit Models, which convert time-domain differential equations into simpler algebraic equations in the s-domain (complex frequency domain). This is crucial for analyzing circuits with energy storage elements (capacitors and inductors) and determining their transient and transfer functions.
  • Foundations of Circuit Analysis: A review of fundamental concepts is provided, including Ohm’s Law, Kirchhoff’s Current Law (KCL), and Kirchhoff’s Voltage Law (KVL), along with an overview of the key mathematical tools required (Algebra, Linear Algebra, Calculus, and Complex Numbers).