Symbolic Circuit Simulation
The idea is to use Maxima to solve circuit equations. Let's start simple:
Solve for I. This turns out to be a general problem in simulation, that is, get the currents on the right side of the equation to sit over to the left by themselves.

In using Maxima, I always like to use variables with three-letter names. This makes things easier to work on in the long run. So the above problem in Maxima looks like this:

(C1) vin=iin*rin;
(D1) 		  vin = iin rin
(C2) solve([D1],[iin]);
(D2) 		   [iin = ---]
I typed in the parts that are in bold, the rest is Maxima.

I have found that it is easier to use Maxima if I avoid using the equals sign. This is easy to do, because the solve() function assumes that the expressions without and equals sign is actually an equation that is implicitly equal to zero. So I prefer it this way:

(C1) vin-iin*rin;
(D1) 			 vin - iin rin
(C2) solve([D1],[iin]);
(D2) 			  [iin = ---]
Here's a voltage divider:
(C1) vin-vout-iin*rin;
(D1) 		    - vout + vin - iin rin
(C2) vout-iin*rsh;
(D2) 		        vout - iin rsh
(C3) solve([D1,D2],[iin,vout]);
			vin	        rsh vin
(D3) 	     [[iin = ---------, vout = ---------]]
		     rsh + rin	       rsh + rin
This set of equations has two Ohm's law equations, two unkowns (iin and vout), and three knowns (vin, rin, and rsh). I always start with a little table like this:

Knowns Unknowns Equations
(implicit = 0)
of Equation
rin iin vin-vout-iin*rin; Ohm's Law
rsh vout vout-iin*rsh; Ohm's Law
I try to line things up so that each row has an equations along with the physical knowns and unknowns that correspond to it. I use a naming convention to get the current and resistor names to be the same, except that the resistors start with an R and the currents start with an I. These conventions help make the equations easy to write.

The networks can get quite large, and they can have many different types of components, such as opamps, transistors, and reactive components. The danger of this approach is that you get very large solutions to the equations, and you wonder, 'What am I going to do with this huge symbolic solution?' These are called wallpaper functions, because the only thing they are good for is printing out and using as wallpaper. Actually, there are nice things that you can do to tame wallpaper functions and make them useful:

I will show how to do all these things, starting with simple circuits. Examples with more complex results can best be shown inside Maxima itself, so I will provide files that you can download and run in Maxima to see how they work.

More later! Meanwhile, Download Maxima and try it out!

Future Sections
More about the divider, KCL, and the vout node.
A larger circuit
reactive components, tank circuit with capacitive coupling.
sensitivity analysis
automation of equation generation
comparison with numerical simulation for results and performance


By toma
Copyright (C) 2003 by Tom Anderson. All Rights Reserved.