Installing Python
steps:-
1.install python in Windows (32 bit,64 bit), MacOS etc as per Operating system requirement.
2.Open cmd as Administrator.
3.select the installation directory of Python
4.Add path to the directory.
5.Install the module describe as under
(i) numpy
(ii)scipy
(iii)matplotlib
Now Run the Code written By Author:---Pankaj Aswal
import numpy as np
'''
Electrical Circuit is
+┌─ R1 ┬─────┬
V R2 R3
-└─────┴─────┴
with following values:
'''
V = 60
R1 = 12
R2 = 3
R3 = 4
'''
1/2. Identify and Assign Nodes
Node 0: Connecting V-R2-R3 (node at the bottom)
Node X: Connecting V-R1 (upper node)
'''
# 3. Apply KCL for Nodes X
# Node X
# simple case with VX = V
VX_nodeX = 1
VY_nodeX = 0
b_nodeX = V
# Node Y
# (VY-VX)/12 + VY/3 + VY/4 =0
# ...
# 28 VY + (-1) VX = 0
VX_nodeY = -(1/R1)*12
VY_nodeY = ((1/R1) + (1/R2) + (1/R3))*12
b_nodeY = 0
# 4. Solve the Linear System
# 1 VX + 0 VY = 28
# - 1 VX + 28 VY = 0
a = np.array([[VX_nodeX, VY_nodeX],[VX_nodeY, VY_nodeY]])
b = np.array([b_nodeX,b_nodeY])
# Solve System
x = np.linalg.solve(a,b)
print(x)
# 5. Solve for other Currents and Voltages
V12 = (x[0] - x[1])/R1
print("v12: ", V12)
V4 = (x[1])/R2
print("v4: ", V4)
V3 = (x[1])/R3
print("v3: ", V3)
import scipy as sp
import matplotlib.pylab as plt
plt.plot(a,b)
plt.show()
Output
1.>>>
===================== RESTART: D:/Desktop/Nodal(new1).py =====================
[60. 7.5]
v12: 4.375
v4: 2.5
v3: 1.875
Output