MSP Simulation Example - Modified Nodal Analysis - without DPsim

Sample Circuit

$R_1$=$1 \Omega$, $R_2$=$1 \Omega$, $R_3$=$10 \Omega$, $R_4$=$5 \Omega$
$I_1$=$1 A$, $V_{0}$=$10 V$

Circuit and Simulation Setup

In [1]:
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:

  1. NA: Stamp the voltage source as real voltage source with the resistor as internal resistance (here R1) and transform it into a current source using Norton transformation (2 nodes involved).
  2. MNA: Stamp the voltage source as ideal voltage source (3 nodes involved)

In the following, we apply the second option.

Modified Nodal Analysis

In [2]:
#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)

Problem formulation

In [3]:
print('Admitance matrix: \n' + str(G))
print('\nSource vector: \n' + str(A_src))
print('\nSize: 4x4')
Admitance matrix: 
[[ 1.  -1.   0.   1. ]
 [-1.   2.1 -0.1  0. ]
 [ 0.  -0.1  0.3  0. ]
 [ 1.   0.   0.   0. ]]

Source vector: 
[[  0.]
 [  0.]
 [  1.]
 [ 10.]]

Size: 4x4

Problem solution

In [4]:
print('Node Voltages: \n' + str(e_nodes[0:3 ,  :]))
print('\nCurrent i_10 through the voltage source: \n'+ str(-e_nodes[1 , :]))
Node Voltages: 
[[ 10.]
 [  5.]
 [  5.]]

Current i_10 through the voltage source: 
[-5.]

LU decomposition of final system matrix

In [5]:
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))
Admitance matrix: 
[[ 1.  -1.   0.   1. ]
 [-1.   2.1 -0.1  0. ]
 [ 0.  -0.1  0.3  0. ]
 [ 1.   0.   0.   0. ]]

Lower triangular matrix: 
[[ 1.          0.          0.          0.        ]
 [-1.          1.          0.          0.        ]
 [ 0.         -0.09090909  1.          0.        ]
 [ 1.          0.90909091  0.3125      1.        ]]

Upper triangular matrix: 
[[ 1.         -1.          0.          1.        ]
 [ 0.          1.1        -0.1         1.        ]
 [ 0.          0.          0.29090909  0.09090909]
 [ 0.          0.          0.         -1.9375    ]]
In [ ]: