Infinite grid of resistors problem (xkcd.com/356/)
Install a CLI SPICE simulator such as ngspice or MacSpice (which also happens to run twice as fast):
brew install ngspice
or
brew install --cask macspice
then compile this Rust script that parses spice outputs
rustc parse_ngspice_output.rs
then run this python script (~40 seconds with the current configuration) to get some results and generate the plots.
python run.py
If everything was a success you should have some .svg
plots in your current directory.
If you want to get straight to a single figure you can just run this instead, passing a moderately big even number like 200
python infinite_grid.py 200 | ngspice
or
ln -s /Applications/MacSpice.app/Contents/MacOS/MacSpice /usr/local/bin
python infinite_grid.py 200 | MacSpice
which, after processing a netlist of 79999 resistors, gives a i(v1) = -1.29315e+00
output, meaning an equivalent resistance of
0.77330549433 Ω
.