# Singular error when putting a current source in series with a capacitor (ngspice)

I am getting singular errors when I simulate a current source in series with a capacitor with the following .cir file:

* Spice netlister for gnetlist
C1 1 0 1
I1 1 0 1
.TRAN 100u 6m


(I understand a farad is huge, just to make the numbers easy. I have tried smaller capacitor values, but they have not helped.)

Based on my analysis,

I = C*(dV/dt)


Integrating, I expect

V = (I*t)/C.


So I would expect increasing voltage in the mV range over time when I plot v(1), but I get the following error at the below of this message. When I change the C1 into an R1, no error is observed at all. What is going on?

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

Warning: singular matrix:  check nodes 1 and 1

Note: Starting dynamic gmin stepping
Trying gmin =   1.0000E-03 Note: One successful gmin step
Trying gmin =   1.0000E-04 Note: One successful gmin step
Trying gmin =   1.0000E-05 Note: One successful gmin step
Trying gmin =   1.0000E-06 Note: One successful gmin step
Trying gmin =   1.0000E-07 Note: One successful gmin step
Trying gmin =   1.0000E-08 Note: One successful gmin step
Trying gmin =   1.0000E-09 Note: One successful gmin step
Trying gmin =   1.0000E-10 Note: One successful gmin step
Trying gmin =   1.0000E-11 Note: One successful gmin step
Trying gmin =   1.0000E-12 Note: One successful gmin step
Trying gmin =   1.0000E-12 Note: One successful gmin step
Warning: singular matrix:  check nodes 1 and 1

Warning: Dynamic gmin stepping failed
Note: Starting source stepping
Supplies reduced to   0.0000% Warning: singular matrix:  check nodes 1 and 1

Trying gmin =   1.0000E-02 Note: One successful gmin step
Trying gmin =   1.0000E-03 Note: One successful gmin step
Trying gmin =   1.0000E-04 Note: One successful gmin step
Trying gmin =   1.0000E-05 Note: One successful gmin step
Trying gmin =   1.0000E-06 Note: One successful gmin step
Trying gmin =   1.0000E-07 Note: One successful gmin step
Trying gmin =   1.0000E-08 Note: One successful gmin step
Trying gmin =   1.0000E-09 Note: One successful gmin step
Trying gmin =   1.0000E-10 Note: One successful gmin step
Trying gmin =   1.0000E-11 Note: One successful gmin step
Trying gmin =   1.0000E-12 Note: One successful gmin step
Note: One successful source step
Supplies reduced to   0.1000% Warning: singular matrix:  check nodes 1 and 1

Supplies reduced to   0.0000% Warning: singular matrix:  check nodes 1 and 1

Warning: source stepping failed

Transient solution failed -

Last Node Voltages
------------------

Node                                   Last Voltage        Previous Iter
----                                   ------------        -------------
1                                                 0                    0

doAnalyses: iteration limit reached

run simulation(s) aborted


Many circuit simulators attempt to find a DC operating point prior to executing a transient analysis. Basically, they replace inductors with short circuits and capacitors with open circuits and then solve the remaining circuit.

Your circuit has no stable DC point (open-circuit current source) and this process fails. Usually, there's a way to tell the simulator to skip the initialization step and specify starting conditions (e.g., Vcap = 0V) explicitly.

SPICE simulations begin by finding a d.c. solution at t=0. At d.c. the current through a capacitor is zero so there is no solution for a non-zero current source in series with a capacitor. Change your constant current source to a source that has an initial value of 0.0A and then ramps up quickly to the desired value.

Another workaround would be to add a high ohm resistor in parallel to the capacitor, maybe 1M or 1G or so. Experiment a bit (same goes for @Joe Hass' answer) and see how much (or how little) the result changes.

• There is a gotcha with Spice, if you enter 1m it will substitute it for 1 milli. If you want to enter 1 mega you have to enter 1meg. Commented Jan 4, 2014 at 13:10

Use the .IC statement.

.IC Statement This statement provides an alternative way to specify initial conditions of nodes (and thus over capacitors).

 .IC Vnode1 = value Vnode2 = value etc.


so .IC V(1) = 0

* Spice netlister for gnetlist
C1 1 0 100UF
I1 1 0 0.5
.IC V(1)=0
.OP
.TRAN 100u 6m
.print tran V(1,0)
.end


And the result is

run simulation(s) aborted * spice netlister for gnetlist

## Index time v(1)

0 0.000000e+00 0.000000e+00
1 6.000000e-07 -3.00000e-03
2 1.200000e-06 -6.00000e-03
3 2.400000e-06 -1.20000e-02
4 4.800000e-06 -2.40000e-02
5 9.600000e-06 -4.80000e-02
6 1.920000e-05 -9.60000e-02
7 3.840000e-05 -1.92000e-01
8 7.680000e-05 -3.84000e-01
9 1.536000e-04 -7.68000e-01
10 2.536000e-04 -1.26800e+00
11 3.536000e-04 -1.76800e+00
12 4.536000e-04 -2.26800e+00
13 5.536000e-04 -2.76800e+00
14 6.536000e-04 -3.26800e+00
15 7.536000e-04 -3.76800e+00
16 8.536000e-04 -4.26800e+00
17 9.536000e-04 -4.76800e+00
18 1.053600e-03 -5.26800e+00
19 1.153600e-03 -5.76800e+00
20 1.253600e-03 -6.26800e+00
21 1.353600e-03 -6.76800e+00
22 1.453600e-03 -7.26800e+00
23 1.553600e-03 -7.76800e+00
24 1.653600e-03 -8.26800e+00
25 1.753600e-03 -8.76800e+00
26 1.853600e-03 -9.26800e+00
27 1.953600e-03 -9.76800e+00
28 2.053600e-03 -1.02680e+01
29 2.153600e-03 -1.07680e+01
30 2.253600e-03 -1.12680e+01
31 2.353600e-03 -1.17680e+01
32 2.453600e-03 -1.22680e+01
33 2.553600e-03 -1.27680e+01
34 2.653600e-03 -1.32680e+01
35 2.753600e-03 -1.37680e+01
36 2.853600e-03 -1.42680e+01
37 2.953600e-03 -1.47680e+01
38 3.053600e-03 -1.52680e+01
39 3.153600e-03 -1.57680e+01
40 3.253600e-03 -1.62680e+01
41 3.353600e-03 -1.67680e+01
42 3.453600e-03 -1.72680e+01
43 3.553600e-03 -1.77680e+01
44 3.653600e-03 -1.82680e+01
45 3.753600e-03 -1.87680e+01
46 3.853600e-03 -1.92680e+01
47 3.953600e-03 -1.97680e+01
48 4.053600e-03 -2.02680e+01
49 4.153600e-03 -2.07680e+01
50 4.253600e-03 -2.12680e+01
51 4.353600e-03 -2.17680e+01
52 4.453600e-03 -2.22680e+01
53 4.553600e-03 -2.27680e+01
54 4.653600e-03 -2.32680e+01

## Index time v(1)

55 4.753600e-03 -2.37680e+01
56 4.853600e-03 -2.42680e+01
57 4.953600e-03 -2.47680e+01
58 5.053600e-03 -2.52680e+01
59 5.153600e-03 -2.57680e+01
60 5.253600e-03 -2.62680e+01
61 5.353600e-03 -2.67680e+01
62 5.453600e-03 -2.72680e+01
63 5.553600e-03 -2.77680e+01
64 5.653600e-03 -2.82680e+01
65 5.753600e-03 -2.87680e+01
66 5.853600e-03 -2.92680e+01
67 5.953600e-03 -2.97680e+01
68 6.000000e-03 -3.00000e+01

CPU time since last call: 0.024 seconds.

Total CPU time: 0.024 seconds.

Total DRAM available = 7925.503906 MB. DRAM currently available = 4380.695312 MB. Total ngspice program size = 14.254883 MB. Resident set size = 2.011719 MB. Shared ngspice pages = 1.771484 MB. Text (code) pages = 1.333008 MB. Stack = 0 bytes. Library pages = 268.000 kB.