1
\$\begingroup\$

I want to make software that would be capable of solving electrical circuits.

Something like CircuitLab or LtSpice.

I have a good background in electrical circuit solving methods and programing as well. But I struggle on combining the two of these.

To be specific my question consists of two parts:

  1. Are there any topics that direct to this thematic i.e. programming algorithms for solving electrical circuits?

  2. Are there any open source software already written that I could use as reference?

I did do research before posting this question here, but didn't find any satisfying results, so I am asking this question in hope that I can benefit from experienced users in this topic from this community.

\$\endgroup\$
4
  • 4
    \$\begingroup\$ Please, please don't reinvent the wheel. Write a dead-easy front-end for SPICE. \$\endgroup\$ Sep 20, 2014 at 21:43
  • \$\begingroup\$ I would like to do this in educational purposes, but thank you for noting front-end for SPICE, I'll check it. \$\endgroup\$
    – balboa
    Sep 20, 2014 at 21:49
  • \$\begingroup\$ Ngspice compiles under GNU/Linux, BSD, Windows and MacOS X. In more than ten years of development activity many bug have been fixed and several extensions to the spice3f have been developed or integrated ... Not your average summer holiday project. \$\endgroup\$
    – jippie
    Sep 20, 2014 at 21:55
  • \$\begingroup\$ It may be worth adding SPICE 2 and SPICE 3 source code is Open Source and available too. Though +1 for 'don't reinvent the wheel' \$\endgroup\$
    – gbulmer
    Sep 20, 2014 at 23:44

1 Answer 1

4
\$\begingroup\$

Certainly writing a front-end to a SPICE simulator is more practical (as pointed out in the comments), but if you're really interested in the nitty-gritty details:

One common tool for performing computational circuit analysis is using modified nodal analysis (MNA). This is a slight variation of nodal analysis to systematically setup voltage sources by adding an unknown current through the voltage source that needs to be solved for. Erik Cheever has a nice set of pages on how to do this for basic DC circuits, as well as how to extend this to steady-state AC and dependent sources.

Transient simulations and non-linear components are a bit funner (harder) to handle. One approach to simulate transients is to make approximations of how transient components behave, and do a dc solve/integrate over time process. For example, here is a post of how I approximated capacitors and inductors to simulate transmission line effects (yes, I know there are better models than the most basic conceptual model, but none really capture the interior).

Non-linear components simply modify the solve step: instead of solving a linear system of equations, you must now solve a non-linear system using some technique such as the Newton-Raphson method. These methods work best when you don't provide discontinuous responses (i.e. use an exponential to approximate a diode V-I curve instead of a step function, etc.).

An alternative approach to MNA is sparse tableau analysis. I personally don't have much, if any experience with this approach other than knowing it exists. More notes on MNA and sparse tableau analysis can be found here.

\$\endgroup\$
3
  • \$\begingroup\$ It may be worth noting that components whose inputs draw zero current and whose outputs behave as voltage or current sources that are controlled by the previous state of the their inputs may be simulated much more easily than those which need to model "instantaneous" behavior. \$\endgroup\$
    – supercat
    Sep 20, 2014 at 23:00
  • 1
    \$\begingroup\$ Just note that Erik Cheever's page has a way better version now, at lpsa.swarthmore.edu/Systems/Electrical/mna/MNA1.html. \$\endgroup\$
    – jcoppens
    Apr 22, 2020 at 17:11
  • \$\begingroup\$ thanks, I updated the link. \$\endgroup\$ Apr 23, 2020 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.