Sub topic 12
Verifying the Result with a Simulator
This chapter assumes you can write a basic SPICE netlist (element lines, node names, .op) and that you have already solved the two-source circuit from the worked example by hand. Any SPICE-family simulator works. The commands below use ngspice.
Why simulate a hand result
A hand solution can be wrong because of a sign error, a source deactivated the wrong way, or a mislabeled node. A simulator solves the full circuit with no deactivation step, so it gives an independent answer to compare against. It can also run each single-source case, which lets you check every partial result as well as the final sum.
The circuit as a netlist
The circuit is V1 (12 V) in series with R1 (4 Ω) into node a. R2 (6 Ω) runs from a to ground, and I1 (2 A) injects current into a.
* Superposition check: V1 and I1 both active
V1 n1 0 DC 12
R1 n1 a 4
R2 a 0 6
I1 0 a DC 2
.op
.endSPICE defines a current source as pushing current from its first node, through the source, to its second node. The line I1 0 a DC 2 therefore drives 2 A into node a. Writing I1 a 0 DC 2 would reverse the direction and give a different answer. Check this first when a result is off.
Run it in batch mode:
ngspice -b full.cirThe operating-point output should list a at 12 V and n1 at 12 V.
Deactivating sources in the simulator
Do not delete a source from the netlist. Set its value to zero, which deactivates it in exactly the way superposition requires:
| Source | Set to | Equivalent element |
|---|---|---|
| Voltage source | `DC 0` | Short circuit |
| Current source | `DC 0` | Open circuit |
A 0 V source is a wire, and a 0 A source carries no current. Keeping the element also leaves its current available to print. With this approach, all three runs use the same topology and differ only in two numbers.
Running the three cases
Create two more files from the one above.
V1 only (v1_only.cir):
* Only V1 active; I1 deactivated (0 A = open circuit)
V1 n1 0 DC 12
R1 n1 a 4
R2 a 0 6
I1 0 a DC 0
.op
.endI1 only (i1_only.cir):
* Only I1 active; V1 deactivated (0 V = short circuit)
V1 n1 0 DC 0
R1 n1 a 4
R2 a 0 6
I1 0 a DC 2
.op
.endExpected node voltages at a:
| Run | V(a) |
|---|---|
| V1 only | 7.2 V |
| I1 only | 4.8 V |
| Both active | 12.0 V |
The first two rows sum to the third. If they do not, one of the three netlists differs from the circuit you analyzed by hand.
Checking currents and signs
Voltages alone can hide a sign error. The current through V1 is more revealing. SPICE reports a voltage source's current as positive when it flows into the positive terminal. Add print i(V1) inside a .control block, or read it from the .op listing, and expect these values:
- V1 only: −1.2 A, because the source delivers 12 V / 10 Ω = 1.2 A out of its positive terminal.
- I1 only: +1.2 A, because 4.8 V across R1 (4 Ω) pushes 1.2 A back into the shorted source.
- Both active: 0 A, because VA equals V1 and no current flows through R1.
The partial currents cancel to zero. A hand calculation that gives a nonzero total here has a sign error in one of its partial results.
Power is not checked by adding runs
The simulator can also show why partial powers do not add. The power in R2 from the full run is 12² / 6 = 24 W. Adding the powers from the two single-source runs gives 7.2² / 6 + 4.8² / 6 = 12.48 W. Superposition applies to voltages and currents, not to power. Always compute power from the full run, or from the summed voltage or current.
Common errors
- Reversed current source. The node order in the
I1line sets the direction. Confirm it matches your hand-drawn arrow. - Deleted instead of zeroed sources. Removing a voltage source leaves an open circuit instead of a short. This breaks the circuit and often leaves nodes floating.
- Missing ground. SPICE requires a node named
0. Without it the run fails or reports a singular matrix. - Dependent sources. If your circuit has one, leave it active in every run. Set only the independent sources to zero.
Exercise
In the I1-only run, the netlist sets V1 to DC 0. A classmate says to delete the V1 line to "turn it off". What goes wrong, and what value of V(a) should the correct run report?
Show answer
Deleting V1 replaces the voltage source with an open circuit, but a deactivated voltage source must be a short circuit. Without V1, R1 would dangle from node a and carry no current, so V(a) would be 2 A × 6 Ω = 12 V, which is wrong. The correct run, with V1 set to DC 0, puts R1 and R2 in parallel (2.4 Ω) and reports V(a) = 2 A × 2.4 Ω = 4.8 V.