Text[" Incidence matrix Aa[i,j] -> graph G(i,j); i nodes, j edges Aa[i,j]={ 1, if edge j is directed towards node i, Aa[i,j]={-1, if edge j is directed from node i, Aa[i,j]={ 0, if edge j is not incident to node i. "] a = { {-1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, { 0, 1, 0, 0, 0, -1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 1, 1, -1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 1, 1, 0, -1, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, -1, 0, 0, -1, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, -1, 0, 0, 0, 0, -1, 0}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, -1, 0, -1, 0, 0}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, -1, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}}; A = Drop[Aa, {1, 1}] ; MatrixForm[A] Text["Multiply A by its transpose, Transpose[A] to get the Laplacian \ (or Kirchhoff) matrix K"] K = A.Transpose[A]; MatrixForm[K] Text["Perform LU decomposition on K, to factor it into an upper (u) \ and a lower (l) triangular matrix and diagonal matrix"] {lu, p, c} = LUDecomposition[K]; det = Tr[lu, Times] Text["The V matrix is equal to determinant* Inverse matrix of K and \ gives the (full)voltages for nodes satisfying Kirchhoff's 1st law"] V = det*Inverse[K]; MatrixForm[V] Text["Dividing rows or columns by GCD , we get reduced voltages - \ this step is not necessary"] W = Apply[GCD, V, {1}] Y = MatrixForm[V/W] Text["The triple matrix product A.V.A gives the edge full current \ solutions matrix F"] F = Transpose[A].V.A; MatrixForm[F] Text["Dividing rows or columns of F by the GCD of each row we get a \ reduction vector, needed to reduce the full currents so we get \ tilings in smallest solutions"] R = Apply[GCD, F, {1}] Text["Dividing the full currents matrix F by reduction vector R gives \ the reduced currents matrix B, which provides all the solutions in \ terms of the sizes of the edge currents. Edge currents become square \ sizes in the squared square. The last row of the B matrix is \ Duijvestijn's 112 squared square, with all the square sizes in \ reduced (GCD=1) size. The other rows are other squared \ rectangles, and the non-diagonal entries are element (square) sizes, and the width of the rectangle is the \ diagonal entry in each row, once we know the width we can work out \ the height from the determinant. In the case of a squared square w = h = diagonal entry."] Text["Now we substitute the values of the edge currents from matrix \ B, one row at a time, into the edges of the graph we started with, \ this gives us the 'Smith Diagram' of the squared square, and we can \ now easily draw or construct the squared square."] B = MatrixForm[F/R]