
Task

Given    10×10    grid nodes   (as shown in the image)   interconnected by    1Ω    resistors as shown,

find the resistance between points   A   and   B.



See also

   (humor, nerd sniping)   xkcd.com cartoon


N = 10;
NN = N*N;
G = sparse(NN, NN);
 
node = 0;
for row=1:N;
    for col=1:N;
	node++;
	if row > 1
	    G(node, node)++;
	    G(node, node - N) = -1;
	end
	if row < N;
	    G(node, node)++;
	    G(node, node + N) = -1;
	end
	if col > 1
	    G(node, node)++;
	    G(node, node - 1) = -1;
	end
	if col < N;
	    G(node, node)++;
	    G(node, node + 1) = -1;
	end
    end
end
 
current = sparse(NN, 1);
 
Ar = 2; Ac = 2; A = Ac + N*( Ar - 1 );
Br = 7; Bc = 8; B = Bc + N*( Br - 1 ); 
current( A ) = -1;
current( B ) = +1;
 
voltage = G \ current;
 
VA = voltage( A );
VB = voltage( B );
 
full( abs( VA - VB ) )