# computer analysis of circuit networks

Discussion in 'Electronic Basics' started by [email protected], Jan 8, 2006.

1. ### Guest

Hi there

I am wanting to write a program that, given a network, can calculate
current, voltage, etc over all components and branches in the network.
At the moment, I am just concentrating on linear DC networks that have
nothing but voltage and/or current sources, and resistors. I'm
ignoring capacitive and inductive components for the time being

In a circuit analysis textbook I've got, it says that branch current
analysis can solve any linear DC network, so this is the algorithm I
have chosen for the program. With voltage sources and resistors this
seems to be no problem, as you are using KVL around each independant
loop of the circuit, plus a couple of KCL equations, then you solve
them simulataneously.

I get stuck with current sources though. for example the following:

-----R1------------------
| | |
| | |
V C R2
| | |
| | |
---------------------------

Lets say V is a 6V battery, R1 is 2 ohms, C is a 2A current source and
R2 is a 5 ohm resistor

With branch analysis, there should be two KVL eqns and one KCL eqn.
But how can you do KVL around a loop with current sources in? I know
that you could convert C into a voltage source through source
conversion, but what if you cannot do a source conversion, such as when
there is not a convenient parallel resistor. i suppose what im asking
for is a surefire algorithm that can be used in a computer program (ie
generic and doesn't rely on human intuition) that will solve any
network. Any hints or open source programs that can be of help are
appreciated...

cheers
Michael

2. ### Guest

The following two pages have some good tips:

http://engr.calvin.edu/courses/engr204/2000/examples/NodeVoltageMeshCurrent/theory.htm
http://www.eas.asu.edu/~holbert/ece201/recipes.html

3. ### Kevin AylwardGuest

Its called...er... SPICE...

Why do you want to reinvent the wheel? Its all been done for 30 years.

The soucce code can be obtained from many sources, e.g. ngspice

http://ngspice.sourceforge.net/

Even the my windows version XSpice engine can be ran standalone to do
this if that's all you are after.

Kevin Aylward

http://www.anasoft.co.uk
SuperSpice, a very affordable Mixed-Mode
Windows Simulator with Schematic Capture,
Waveform Display, FFT's and Filter Design.

4. ### Charles SchulerGuest

Michael, use nodal analysis if you want to tackle this yourself.

to use it.

5. ### Guest

I know Kevin, I used Spice at uni. That's not the point.

Call me unhinged, but sometimes I like to understand how things work,
especially algorithms. I am after all a programmer by trade...

Anyhow, I found out what Spice uses, an algorithm called modified nodal
analysis (MNA). Right now, I don't completely understand the
mathematics behind it, but I know enough to implement it in software.