Changing parameters with alter
A script that reruns an RC circuit with different resistances and sources.
A .control script that uses alter in a foreach loop to set R1 to 330Ω, 1kΩ and 3.3kΩ, running a transient each time, and then changes the source to a 750Hz sine wave.
- v(2), run 1
- v(2), run 2
- v(2), run 3
- v(2), run 4
The circuit: examples/alter_demo.cir
alterdemo.cir
vin 1 0 pulse (0.0V 1.0V 2ms) ac 1.0 dc 0.0
r1 1 2 1.0K
c1 2 0 1.0u
.control
* perform a transient analysis
foreach rvalue 330 1.0k 3.3k
alter @r1[resistance] = $rvalue
tran 0.1ms 10ms 0.0ms 0.2ms
* draw a graph of the voltage at node 2 vs time.
plot v(2) title "R1 = {$rvalue}ohm, pulse"
end
* Change to a sinewave source
alter @vin[sin] = [0.0, 1.0, 750]
tran 0.1ms 10ms 0.0ms 0.2ms
plot v(2) title "R1 = {$rvalue}ohm, sinewave"
.endc
.end
Run it with spice alter_demo.cir, or open it with File › Load netlist in the Qt window. The plots and output above were made by util/mkexamples.py, which runs the deck in batch mode. All examples