Create Circuit Simulation

I wrote the simulation engine that powers CircuitLab from scratch: from the sparse matrix library up through component models and simulation modes. My co-founder wrote the front-end. It ended up being an unbelievably huge programming project, but one I'm quite proud of. If you're up for the challenge, writing a circuit simulator may be one of the most rewarding programming projects you'll ever tackle.

At a high level, you just need to:

  1. Turn a network of components into a system of equations (non-linear differential equations).
  2. Numerically solve the system of equations (using sparse matrix techniques).

I don't know of an online tutorial, but I've tried to document a lot of this as I write the "Ultimate Electronics" textbook, especially in Chapter 2. There are also a number of 1990s-era books on the topic of circuit simulation, though I don't have them handy at the moment.

My suggestion would be to start from only voltage sources and resistors, and continue building from there. Good luck.


I doubt there are online tutorials because it's something pretty specific.

However, one source of information you can definitely use is open source code. One I know of is SpicePy - it's written in Python, but it's very well documented, although the Python language is very descriptive just by itself. You can use such library in your Python code or though the Telegram Bot.

What you'll need is some sort of way to describe the topology of your circuit. One common approach is the use of netlists, which are essentially text that describe each component in the circuit and how it's connect to the other ones (e.g. through node numbers). You can use this strategy or whatever one seems easier for you to take; parsing it and making it an actual graph (i.e. is it meaningful?) out of it might take you some time.

After that, one common way to analyze circuits in simulators is nodal analysis; then resort to some linear algebra library to solve the system of equations (which will surely be linear), such as Math.Net.