A Rigorous, High-Precision DC Circuit Analysis Tool using Modified Nodal Analysis (MNA)
- Overview
- Key Features
- Mathematical Foundations
- Numerical Methods
- Workflow
- Example Analysis
- Verification & Validation
- Advanced Extensions
- Future Roadmap
The Advanced Circuit Simulator is designed to perform accurate, stable, and verifiable DC circuit analysis using Modified Nodal Analysis (MNA). It’s not just a black-box solver — it’s an educational and professional tool that lets you:
- See the full equation system your circuit produces
- Understand matrix assembly from physical components
- Verify your results against KCL, KVL, and power conservation
- Extend to AC, nonlinear, and transient analyses
- 🔍 Accurate MNA Implementation for DC steady-state analysis
- 📐 Union-Find Node Detection for correct topology mapping
- ⚙️ LU Decomposition with Partial Pivoting for stable solving
- 📊 Post-Processing: per-component currents & power
- ✅ Automatic Verification of physical conservation laws
- 📈 Residual Norm & Condition Number reporting
- 🔄 Ground Node Reduction for efficiency
- 🛠 Educational Mode showing intermediate matrices
Problem Setup Given a circuit with:
-
$n$ non-ground nodes -
$m$ voltage sources
The MNA formulation is:
\begin{bmatrix} I_s \ V_s \end{bmatrix} $$
Where:
-
$G$ : Conductance matrix (Ohm’s law contributions) -
$B$ : Voltage source incidence matrix -
$I_s$ : Current injection vector -
$V_s$ : Voltage source vector
Dimension:
The simulator is numerically robust thanks to careful preprocessing and solving strategies.
We select one node as reference (ground) and remove its row and column from the MNA system.
-
Why?
- Ground voltage is fixed (
$V_g = 0$ ) → no need to solve for it - Reduces size from
$(n+m)$ to$(n+m-1)$ - Improves conditioning by removing a trivial equation
- Ground voltage is fixed (
We solve:
Using the factorization:
-
$L$ : Lower triangular (1’s on diagonal) -
$U$ : Upper triangular -
$P$ : Row permutation matrix (from pivoting)
Partial Pivoting:
- Finds the largest pivot element in the current column
- Swaps rows to place it on the diagonal
- Prevents division by small numbers
- Reduces round-off error growth
Algorithm (Doolittle with Pivoting):
-
For column
$k$ :-
$p = \arg\max_{i \ge k} |A[i,k]|$ -
Swap rows
$k$ and$p$ in$A$ , update$P$ -
For rows
$i > k$ :$$ L[i,k] = \frac{A[i,k]}{A[k,k]} $$
Update:
$$ A[i,j] = A[i,j] - L[i,k] \cdot A[k,j] $$
-
-
After factorization:
-
Forward substitution:
$L \cdot y = P \cdot z_{red}$ -
Backward substitution:
$U \cdot x_{red} = y$
-
Forward substitution:
Complexity:
-
$O((n+m)^3)$ worst-case for dense systems - Reduced by ground removal
After solving:
- Goal:
$r \leq 10^{-10}$ - Large residual → possible ill-conditioning or singularity
The simulator computes:
- High
$\kappa(A)$ → sensitive to rounding & component tolerances - Helps detect unstable circuits before trusting results
graph TD;
A[Component & Wire Input] --> B[Node Identification (Union-Find)]
B --> C[MNA Matrix Assembly (G, B, I_s, V_s)]
C --> D[Ground Node Reduction]
D --> E[LU Decomposition & Solve]
E --> F[Post-Processing (Currents & Powers)]
F --> G[Verification (KCL, KVL, Power)]
Circuit:
- Vs = 12 V
- R1 = 1 kΩ
- R2 = 2 kΩ
Results:
| Quantity | Value |
|---|---|
| V₂ | 8 V |
| I | 4 mA |
| P_R1 | 16 mW |
| P_R2 | 32 mW |
| P_Vs | -48 mW |
✅ KCL/KVL & Power Conservation verified.
- KCL: Currents at every node sum to ≈ 0
- KVL: Loop voltages sum to ≈ 0
- Power: Total supplied = total consumed
- Residual Norm: Reports how close numerical solution is to exact
- Condition Number: Alerts on stability risk
- 🌀 AC Phasor Analysis
- 📉 Nonlinear Components with Newton-Raphson
- 🎯 Sensitivity & Monte Carlo parameter analysis
- ⚡ Sparse Matrix Solver for large-scale systems
MIT License — free to use, modify, and distribute.
.gif)