-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path250428 ExemploResistor2.py
More file actions
77 lines (59 loc) · 1.5 KB
/
Copy path250428 ExemploResistor2.py
File metadata and controls
77 lines (59 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import numpy as np
import sympy as sp
R1 = sp.Symbol('R1')
R2 = sp.Symbol('R2')
R3 = sp.Symbol('R3')
R4 = sp.Symbol('R4')
R5 = sp.Symbol('R5')
A = sp.Symbol('A')
G = sp.Symbol('G')
I = sp.Symbol('I')
V = sp.Symbol('V')
def estampaResistor(a,b,R,Gn):
Gn[a,a] = Gn[a,a] + 1/R
Gn[a,b] = Gn[a,b] - 1/R
Gn[b,a] = Gn[b,a] - 1/R
Gn[b,b] = Gn[b,b] + 1/R
return Gn
def estampaFonteTensao(a,b,i_v,V,Gn,I):
Gn[a,i_v,] += 1
Gn[b,i_v] += -1
Gn[i_v,a] += -1
Gn[i_v,b] += 1
I[i_v] += "-V"
return Gn
def estampaFonteCorrenteControladaPorTensao(a,b,c,d,Gn):
Gn[a,c] += "Gm"
Gn[b,c] += "-Gm"
Gn[a,d] += "-Gm"
Gn[b,d] += "Gm"
return Gn
def estampaFonteCorrenteControladaPorCorrente(a,b,c,d, i, A,Gn):
Gn[a,i] += 1
Gn[b,i] += -1
Gn[i,a] += -1
Gn[i,b] += 1
Gn[i,c] += A
Gn[i,d] += -A
return Gn
def estampaFonteCorrente(a,b,I,Gn):
I[a] = I
I[b] = I
return Gn
I = np.array([0,0,0,0,0,0,0,0])
Gn = np.zeros([8,8], dtype=object)
Gn = estampaResistor(0,1,R1,Gn)
Gn = estampaResistor(2,4,R2,Gn)
Gn = estampaResistor(1,3,R3,Gn)
Gn = estampaResistor(4,0,R4,Gn)
Gn = estampaResistor(5,0,R5,Gn)
Gn = estampaFonteTensao(1,2,6,V,Gn,I)
Gn = estampaFonteCorrente(4,5,I,Gn)
Gn = Gn[1:,1:]
# Convert to sympy Matrix for proper formatting
Gn_matrix = sp.Matrix(Gn)
print("Conductance Matrix:")
sp.pprint(Gn_matrix)
# Print current vector
print("\nCurrent Vector:")
print(I)