;
X12 = repmat(xpos(1,:)',1,n);
X21 = repmat(xpos(2,:),n,1);
X22 = repmat(xpos(2,:)',1,n);
LL  = abs(X11-X12) + abs(X21-X22);
L   = tril(LL);
L   = L(find(L&gt;0));

<span class="comment">%</span>
<span class="comment">% Construct the capacitance and conductance matrices</span>
<span class="comment">%   C(x) = C0 + w11 * C1 + w21 * C2 + ...</span>
<span class="comment">%   G(x) = G0 + w11 * G1 + w21 * G2 + ...</span>
<span class="comment">% and we assemble the coefficient matrices together as follows:</span