如何使用Python解决以下系统?

问题描述 投票:0回答:1

我不知道如何求解以下系统,然后提取值 v_1、v_2、v_3 和 v_n 用于打印中的计算。

import cmath
import math
import numpy as np

r3 = math.sqrt(3)
pp = cmath.exp(-1j * math.pi * 2 / 3)
U = 400
U_ph = U / r3
U_a = U_ph
U_b = U_a * pp
U_c = U_b * pp

S_HP = 3e3 - cmath.sqrt((3e3 / 0.95) ** 2 - 3e3 ** 2) * 1j
S_PV = -3.6e3 + 0j
S_EV = 16 * 400 * r3 + 0j

Z = 0.3 + 0.1j
Z_HP = (U_ph**2 / S_HP).conjugate()
Z_PV = (U_ph**2 / S_PV).conjugate()
Z_EV = (U_ph**2 / S_EV).conjugate()

v_1 = ((U_a/Z) + (v_n/Z_HP)) / ((1/Z) + (1/Z_HP))
v_2 = ((U_b/Z) + (v_n/Z_PV)) / ((1/Z) + (1/Z_PV))
v_3 = ((U_c/Z) + (v_n/Z_EV)) / ((1/Z) + (1/Z_EV))
v_n = ((v_1/Z_HP) + (v_2/Z_PV) + (v_3/Z_EV)) / ((1/Z) + (1/Z_HP) + (1/Z_PV) + (1/Z_EV))

print(f"\n |v1-vn| = {np.abs(v_1 - v_n):.0f} V.")
print(f"\n |v2-vn| = {np.abs(v_2 - v_n):.0f} V.")
print(f"\n |v3-vn| = {np.abs(v_3 - v_n):.0f} V.")

我尝试使用 sympy 的符号来解决问题,但无法以 int 或 float 值的形式提取 v_1、v_2、v_3 和 v_n 的值。

python sympy equation-solving
1个回答
0
投票

使用 sympy.solve 求解方程组:

import cmath
import math
import numpy as np
import sympy as sp

r3 = math.sqrt(3)
pp = cmath.exp(-1j * math.pi * 2 / 3)
U = 400
U_ph = U / r3
U_a = U_ph
U_b = U_a * pp
U_c = U_b * pp

S_HP = 3e3 - cmath.sqrt((3e3 / 0.95) ** 2 - 3e3 ** 2) * 1j
S_PV = -3.6e3 + 0j
S_EV = 16 * 400 * r3 + 0j

Z = 0.3 + 0.1j
Z_HP = (U_ph ** 2 / S_HP).conjugate()
Z_PV = (U_ph ** 2 / S_PV).conjugate()
Z_EV = (U_ph ** 2 / S_EV).conjugate()

v_1, v_2, v_3, v_n = sp.symbols("v_1 v_2 v_3 v_n")

solution = sp.solve([
    v_1 - ((U_a/Z) + (v_n/Z_HP)) / ((1/Z) + (1/Z_HP)),
    v_2 - ((U_b/Z) + (v_n/Z_PV)) / ((1/Z) + (1/Z_PV)),
    v_3 - ((U_c/Z) + (v_n/Z_EV)) / ((1/Z) + (1/Z_EV)),
    v_n - ((v_1/Z_HP) + (v_2/Z_PV) + (v_3/Z_EV)) / ((1/Z) + (1/Z_HP) + (1/Z_PV) + (1/Z_EV))
         ],
         [v_1, v_2, v_3, v_n]
)

v_1_val, v_2_val, v_3_val, v_n_val = solution[v_1], solution[v_2], solution[v_3], solution[v_n]

print(f"\n |v1-vn| = {np.abs(v_1_val - v_n_val):.0f} V.")
print(f"\n |v2-vn| = {np.abs(v_2_val - v_n_val):.0f} V.")
print(f"\n |v3-vn| = {np.abs(v_3_val - v_n_val):.0f} V.")

© www.soinside.com 2019 - 2024. All rights reserved.