# symbolic circuit analysis in Sagemath/Mathematica with graph theory/incidence matrix?

Looking for how to go from graph theory directly to solve circuit/nodal analysis. This link has been helpful: graphs and circuits but I seem to be getting lost in the graph theory part. SPICE must do something like this numerically, is there any documentation on the design/algorithms that SPICE uses?

I can build a directed graph in Sagemath/Mathematica by adding vertices/edges.

Sagemath will return the incidence matrix. Or you can enter the incidence matrix directly but for something like a netlist it can be a lot easier to enter nodes, ie. vertices of the graph.

Resistances/impedances go into a diagonal matrix R, known voltages/currents go into a vector.

I'm not clear on finding the spanning tree/re-arranging the incidence matrix. Seems like this should be some standard graph theory or linear algebra functions. You eliminate one row/column and should have a matrix A =[ At I ] where At = edges in the graph spanning tree and I = n x n identity matrix.

• SPICE works by using the Modified Nodal Analysis method for making converting an input circuit to a solvable system of equations. I'm sure there's some rigorous background graph theory, and a similar approach to construct the global system of equations is used in finite element methods. Commented Apr 3, 2016 at 20:30
• Note that the global system is theoretically solvable analytically, though it becomes impractical for anything more than a handful of unknowns (say, more than 6 or 7). Commented Apr 3, 2016 at 20:32

There are several techniques to write the equations describing the behavior of a circuit. Topology-based techniques make use of results from graph-theory. They may be systematized for passive circuits, but the inclusion of active elements is not straightforward. The tableau approach is a systematic technique does not have these limitations but yields a high number of equations (and unknowns). In the modified nodal analysis (MNA) approach, the main unknowns are the nodal voltages (the name comes from this fact) augmented with the currents flowing across certain elements: the voltage sources and inductors. In the MNA, the system of equations is such that there are no negatives powers of s (the Laplace transform variable) in the system matrix. Most, if not all, of the current circuit simulators (for instance, all SPICE variants) are based on MNA as it a) is straightforward to apply to any circuit and b) gives a reasonable number of unknowns.

Symbolic analysis is a different question, and can be based on any analysis technique. For instance, symbolic computation of the determinants arising when solving the MNA system of equations directly gives the the transfer function in symbolic form.