$R_1$=$1 \Omega$, $R_2$=$1 \Omega$, $R_3$=$10 \Omega$, $R_4$=$5 \Omega$
$I_1$=$1 A$, $V_{0}$=$10 V$
import numpy as np
np.set_printoptions(sign=' ')
#Components
R1= 1.0
R2= 1.0
R3= 10.0
R4= 5.0
I_1= 1.0
V_0= 10.0
Derive the admittance matrix G and the source vector A applied in nodal analysis using the matrix stamp approach. Note here, that there are in general two approaches to stamp a voltage source connected in series with a resistor:
In the following, we apply the second option.
#Building source vector
A_src = np.array([[0] ,
[0] ,
[I_1] ,
[V_0]])
#Building admitance matrix
G = np.array([[1/R1, -1/R1 , 0 , 1],
[-1/R1, (1/R1 + 1/R2 + 1/R3) , -1/R3 , 0],
[0 , -1/R3, (1/R3 + 1/R4), 0],
[1, 0, 0, 0]])
#System solution
e_nodes = np.matmul(np.linalg.inv(G),A_src)
print('Admitance matrix: \n' + str(G))
print('\nSource vector: \n' + str(A_src))
print('\nSize: 4x4')
print('Node Voltages: \n' + str(e_nodes[0:3 , :]))
print('\nCurrent i_10 through the voltage source: \n'+ str(-e_nodes[1 , :]))
import scipy.linalg as linalg
import ipywidgets as widgets
P, L, U = linalg.lu(G, permute_l=False, overwrite_a=False, check_finite=True)
print('Admitance matrix: \n' + str(G))
print('\nLower triangular matrix: \n' + str(L))
print('\nUpper triangular matrix: \n'+ str(U))