eCircuit Center 
SPICE Topics 
About SPICE 
SPICE Basics  Running SPICE
 CIRCUIT COLLECTION 
SPICE Commands  SPICE Demos and Downloads 

NODAL ANALYSIS After simulating circuits for some time, I began to ask myself  how does this SPICE program work? What mathematical tricks does the code execute to simulate complex electrical circuits described by nonlinear differential equations? After some searching and digging, some answers were uncovered. At the core of the SPICE engine is a basic technique called Nodal Analysis. It calculates the voltage at any node given all resistances (conductances) and current sources of the circuit. Whether the program is performing DC, AC, or Transient Analysis, SPICE ultimately casts its components (linear, nonlinear and energystorage elements) into a form where the innermost calculation is Nodal Analysis.
WHAT IS NODAL ANALYSIS? Kirchoff discovered this: the total current entering a node equals the total current leaving a node! And, these currents can be described by an equation of voltages and conductances. If you have more than one node, then you get more than one equation describing the same system (simultaneous equations). The trick now is finding the voltage at each node that satisfies all of the equations simultaneously. Circuit Example Here’s a simple circuit example. Another way of stating the KC Law is this: the sum of currents in and out of a node is zero. This makes writing nodal equations a piece of cake. The two equations for the two circuit nodes look like this. Because our mission is to calculate the node voltages, let’s reorganize the equations in terms of V1 and V2. So here sit V1 and V2 in the middle of two different equations. The trick is finding the values of V1 and V2 that satisfy both equations. But how?
SOLUTION #1 – WORK THE EQUATIONS Just roll up your sleeves and solve for V1 and V2. Before we begin we’ll make bookkeeping easy by writing the resistors in terms of total conductance: G11 = 1/R1 + 1/R2, G12 = 1/R2, G21 = 1/R2 and G22 = 1/R2+1/R3. The system equations now look like this. First, solve the second equation for V1 Then, stick this into the first equation and solve for V2 Okay, it’s a little messy, but we’ve got V2 described by circuit conductances and Is only! After V2 is calculated numerically, stick it back into V1 = – G22 ∙V2 / G21 and there you have it, circuit voltages V1 and V2 that satisfy both system equations.
SOLUTION #2 – THE MATRIX Solution #1 looks reasonable for simple circuits, but what about medium or large circuits? The bookkeeping of terms spins out of control quickly. What’s needed is a more methodical and efficient solution: Enter the Matrix. Here’s the set of nodal equations written in matrix form. Or, in terms of total conductances and source currents Treating each matrix as a variable, you can write G ∙ v = i In the matrix world, you can solve for a variable (almost) like any other algebraic equation. Solving for v you get v = G^{}^{1}∙ i Where G^{}^{1} is the matrix inverse of G. ( 1 / G does not exist in the matrix world.) This equation is the central mechanism of the SPICE algorithm. Regardless of the analysis – AC, DC, or Transient – all components or their effects are cast into the conductance matrix G and the node voltages are calculated by v = G^{}^{1}∙ i , or some equivalent method. LINEAR DC ANALYSIS Armed with Nodal Analysis and an Excel spreadsheet, you can perform Linear DC Analysis on the circuit above. Download and open the spreadsheet LINEAR_DC_ANALYSIS.XLS. Enter the circuit values under the variables shaded light blue.
How much voltage would you estimate at nodes 1 and 2?
You can expect V1 = Is ∙ R1 = First, the spread sheet calculates the conductance matrix G
according to the equations
Next, Excel inverts G and multiplies the result G1 by i to get v. ( See how Excels inverts and multiplies matrices below.) G^{}^{1} x i = v
And there you have it, just like the SPICE engine, we’ve computed the circuit’s voltages! Pick other values for R1 like 1 or 100 Ω. Does the output scale up and down as expected? Change R2 or R3. Vary Is or change its polarity. HANDSON DESIGN Try adding another resistor to the circuit. For example, place R4 in parallel with R3. Write out the nodal equations. Then include R3 in the cell formulas that form G. The Excel formulas should effectively calculate the following.
THE SPICE CIRCUIT To verify the results our nodal analysis, you can run a simulation of DC_LINEAR_CKT.CIR. Download the file or copy this netlist into a text file with the *.cir extension. LINEAR_DC_CKT.CIR  SIMPLE CIRCUIT FOR NODAL ANALYSIS * IS 0 1 DC 1A * R1 1 0 10 R2 1 2 1K R3 2 0 1K * * ANALYSIS .TRAN 1MS 10MS * VIEW RESULTS .PRINT TRAN V(1) V(2) .PROBE .END Although it runs a Transient Analysis, it essentially computes a DC Linear Analysis because no nonlinear elements or chargestorage devices exist in the circuit. Plot V(1) and V(2). Utilize the cursor, if needed, to get an accurate measurement. Do the voltages from SPICE and Excel agree?
Excel provides handy matrix functions for getting our hands on the nodal analysis example. Matrix functions are entered like any other Excel function except for one trick. Instead of pressing ENTER after entering a function, you need to hit CTRLSHIFTENTER simultaneously!
THE MATRIX SOLUTION  GOOD NEWS, BAD NEWS The good news is that the matrix form of system equations can be easily expanded to larger circuits. The bad news lies in finding v. There are several paths to answer. Why so many? Some are more efficient then others. Briefly, here are three techniques to solve the matrix equation for v.
WHAT ABOUT VOLTAGE SOURCES? You may have noticed that nodal analysis does not accommodate a voltage source. What can be done? In the early days, voltage sources were defined with a small series resistor, representing the internal resistance of the source. Then, the V with series R was converted into its Norton Equivalent of I with parallel R. This alternate current source fit nicely into the Nodal System and all was right with the world. Later, a clever method was hatched to include voltagedefined components called Modified Nodal Analysis (MNA). In this system, much of the equations looked just like Nodal Analysis with rows of equations added describing the influence of the voltage sources. WANT MORE INFO? Here are some great sources of information on simulation.
For more info on these and other books go to the Bookshop.


About SPICE 
SPICE Basics  Running SPICE
 CIRCUIT COLLECTION 
SPICE Commands 