calcul flux linéaires

This commit is contained in:
Dumbobelix 2023-12-11 15:28:31 +01:00
parent 75488c3fee
commit 57d7148822
2 changed files with 54 additions and 0 deletions

53
opti_continu.py Normal file
View file

@ -0,0 +1,53 @@
import numpy as np
import matplotlib.pyplot as plt
import PyQt5 as qt
# Vn = 4e5 # En V
def make_Y(n):
Y = np.zeros((n, n))
return Y
def connect_Y(x, y, Ys, Yp, Y):
Y[x, y] = -Ys
Y[y, x] = -Ys
Y[x, x] += Ys + Yp
Y[y, y] += Ys + Yp
def spec(n, Y, Vn):
S = np.zeros((n, n))
for i in range(n):
for k in range(n):
if i == k:
S[i, k] = n
else:
S[i, k] = -1
S[i, k] *= Vn**2 * Y[i, k]
return S
def delta_select(i, S):
for k in range(len(S)):
S[i, k] = 0
Y = make_Y(4)
connect_Y(2, 3, 0.1, 0, Y)
connect_Y(1, 3, 0.15, 0, Y)
connect_Y(2, 1, 0.05, 0, Y)
connect_Y(2, 0, 0.05, 0, Y)
connect_Y(3, 0, 0.05, 0, Y)
print("Admittance matrix :")
print(Y)
S = spec(4, Y, 2e5)
print("System matrix :")
print(S)
invS = np.linalg.inv(S)
print(invS)
P = np.array([1000, -500, -250, -250])
P = P * 1e6
print("Power input :")
print(P)
delta = np.dot(invS, P)
print("Delta (rad) :")
print(delta)
print(delta * 180 / 3.1415)

View file

@ -79,6 +79,7 @@ def minimize(f, x0, h=1e-4, step=1e-1, tol=1e-8, N=1e4, echo=False):
return x
def custom_minimize(f, x0, echo=False):
# Fonction avec plusieurs étapes successives de résolution, pour gagner en précision et éviter de diverger
res_app = minimize(f, x0, step=5e-1)
if echo:
print(res_app)