Determine mesh currents for the circuit and apply the method of Diakoptics by removing the branches $Z_7$ and $Z_8$
$z_1$=$1 \Omega$, $z_2$=$1 \Omega$, $z_3$=$1 \Omega$, $z_4$=$1 \Omega$, $z_5$=$1 \Omega$, $z_7$=$1 \Omega$
$z_2$=$1 \Omega$, $z_8$=$1 \Omega$
$E_1$=$20 V$, $E_2$=$3 V$, $E_3$=$5 V$, $E_4$=$-5 V$
import numpy as np
import matplotlib.pyplot as plt
np.set_printoptions(sign=' ')
# Circuit parameters:
z1 =1.0
z2 = 1.0
z3=1.0
z4 = 1.0
z5 = 1.0
z6 = 2.0
z7 = 1.0
z8 = 2.0
E1 = 15.0
E2=3.0
E3=5.0
E4=-5.0
E_orgn = np.array([ [E1],
[E2],
[E3],
[E4]])
Z_orgn = np.array([[(z1+z3+z7), -z3, -z7, 0],
[-z3, (z3+z5+z8), 0, -z8],
[-z7, 0, (z2+z4+z7), -z4],
[0, -z8, -z4, (z4+z6+z8)]])
# Mesh currents:
i_orgn = np.matmul(np.linalg.inv(Z_orgn),E_orgn)
print('Impedance matrix: \n' + str(Z_orgn))
print('\nProblem size: 4x4')
print('\nMesh currents: \n' + str(i_orgn))
# Removed branches
y7 = 1/z7
y8 = 1/z8
Y = np.array([ [y7, 0],
[ 0, y8]])
# Connection matrix
C = np.array([ [-1, 0, 1, 0],
[ 0, 1, 0, -1]])
# Impedance matrix for subsystem 1
Z11 = np.array([[(z1+z3), -z3],
[-z3, (z3+z5)]])
# Impedance matrix for subsystem 2
Z22 = np.array([[(z2+z4), -z4],
[-z4, (z4+z6)]])
# Block-diagonal impedance matrix of the equivalent network
Z = np.block([[Z11, np.zeros((2, 2))],
[np.zeros((2, 2)), Z22]])
E = np.array([[E1],
[E2],
[E3],
[E4]])
print('\nBlock-diagonal impedance matrix of the equivalent network: \n' + str(Z))
# Matrix inverse of impedance matrix of the equivalent network
# The matrix is block-diagonal - we can invert 2 blocks of the size 2x2 independently
Z_inv = np.block([[np.linalg.inv(Z11), np.zeros((2, 2))],
[np.zeros((2, 2)), np.linalg.inv(Z22)]])
print('\nMatrix inversion of the block diagnoal matrix: \n' + str(Z_inv))
# This matrix must be inverted, the size is 2x2
Y_psi = Y + np.matmul(C, np.matmul(Z_inv,C.transpose()))
Y_psi_inv = np.linalg.inv(Y_psi)
# Solution obtained based on the method of diakoptics
i_diak= np.dot(Z_inv,E) - np.matmul( np.matmul(np.matmul(Z_inv,C.transpose()) , np.matmul(Y_psi_inv,C)) , np.matmul(Z_inv,E))
print('\nMesh currents obtained based on diakoptics: \n' + str(i_diak))
print('\nMesh currents obtained based on standard meshed current analysis: \n' + str(i_diak))
The solution obtained by the method of diakoptics is an exact solution of original problem.
Computational effort:
Standard solution requires 1 matrix inversion of matrix size 4x4.
Solution based on diakoptics requires 3 matrix inversions of matrix size 2x2.
If we assume that matrix inversion scales with the cube of the matrix size, the following is valid:
$3*2^3 < 4^3$