# Re: Simulation of RLC circuit

• posted

Hi

> >To continue this discussion about simulation of incremental difference >equations, I was wondering how you could add a power source to the code >that John Larkin came up with. >I have been experimenting with this and I found that merely adding the >voltage like > > > //FOR T = 0 TO 1 STEP DT > // IL = IL + (Vin-Vout) * DT / L > // IR = Vout / R > // IC = IL - IR > // Vout = Vout + IC * DT / C +myVoltage > //NEXT > ... >Here is the circuit I am looking at: > > [Input]--[coil]---|-------|----[output]--| > | | | | > | [cap] [resistor] [voltage] > | | | | > |---------|-------|--------------| > | > [ground]

Let's call the voltage source you label [voltage] "Vsource"

If you hook a voltage source between output and ground, then it will hold output the same as the voltage source. In other words, Vout = Vsource. In terms of the program, it would look like this:

//FOR T = 0 TO 1 STEP DT // IL = IL + (Vin-Vout) * DT / L // IR = Vsource / R // IC = "indeterminate" // Vout = Vsource //NEXT

Note, this probably isn't what you want, and isn't very interesting. If Vin and Vsource are unequal, then you essentially have a short through the coil, which will produce an infinite current in the coil. The capacitor voltage will equal Vsource, and the capacitor current would either be 0 (for DC) or infinite (for AC).

If you assume some source resistance (call it Rsource) in series with your voltage source, then things calm down a bit. Here's what that would look like:

//FOR T = 0 TO 1 STEP DT // IRsource = (Vout-Vsource) / Rsource // IL = IL + (Vin-Vout) * DT / L // IR = Vout / R // IC = IL - IR - IRsource // Vout = Vout + IC * DT / C //NEXT