I have written a circuit simulator that uses Kirchoff's voltage and current laws to solve linear circuits containing capacitors, resistors, inductors and op-amps (where the op-amps are assumed to be linear), but I'd like to add support for diodes and transistors and I'm a bit lost as to how to do it.
My program is essentially an implementation of modified nodal analysis - using the user's specified circuit, I build a series of simultaneous equations into an admittance matrix and solve it for the circuit's input using a sparse solver. It works well for performing small signal ac analysis to calculate transfer functions and noise.
Diodes and transistors are of course non-linear, and must in the latter case have negative feedback applied by the circuit to linearise them. They do not have a (simple) frequency dependent resistance dependency like the passive components I have already implemented, but rather a transconductance set by the bias in the circuit, so my admittance matrix approach doesn't really work for circuits containing diodes and transistors. I think SPICE handles non-linear components by first finding the "dc operating point" of the circuit, then it replaces the non-linear components with equivalent impedances (perhaps with e.g. parasitic capacitance as well) but I don't know how to do that. In my current program, I do not need to calculate the dc operating point because this is implicitly zero due to the presence of only linear components. If anyone can describe the process of calculating the dc operating point of circuits with diodes and transistors, or if they could point me towards any documents or texts that describe how to perform such an analysis (or perhaps some source code in a high level language), I'd be grateful!