# Algorithmic approach for applying Kirchhoff's Rules to circuit analysis

Working with Kirchhoff's rules, I am attempting to device an algorithmic approach to finding the unknowns of the problems, I am of a Computer Science background and I am finding it difficult to identify proper closed loops within the circuit and I am curious if there is a generalized pice of sudo code applicable to these problems, or perhaps a matlab or sympy script available?

• There is an electrical engineering stack exchange, which might be more appropriate. In short, it's easy enough to write such an algorithm (indeed, I've written one before), but the matrix math is often particularly sparse and programs that do this work can have trouble solving every kind of network. Commented Jul 7, 2012 at 19:13
• There is also a beta site for scientific computation for which this question might be a little basic unless you can elaborate on the nature of the networks. As @AlanSE says, the basic problem is not too hard for a undergraduate course but the straight forward approach has pathological failure modes for some classes of networks. Phrases like "ill-conditioned" come up in discussions of the hard cases. Commented Jul 7, 2012 at 19:16
• That type of programming is my specialty! I simply find the manor in which physics is generally presented very difficult to comprehend. To be able to look at concise piece of code would do a lot for my understanding of these problems. I'll take a look on the electrical engineering stack exchange. Commented Jul 7, 2012 at 19:17
• To expand on @dmckee's suggestion, to give the basics you probably want to specify the components you want to include and give a few examples to demonstrate the intended scale. Understand that including some... uniquely nonlinear components could make solving the system basically unworkable. Even a pure voltage/current source easily results in combinations that are literal contradictions. Commented Jul 7, 2012 at 19:40
• One approach is Modified Nodal Analysis: en.wikipedia.org/wiki/Modified_nodal_analysis Qucs has a nice pedagogical discussion of implementation: qucs.sourceforge.net/tech/node1.html Commented Jul 7, 2012 at 22:26