Hi, there. When I use sympy to solve high order and nonlinear equations, I found that it is too slow to get all the result. I guess it is because the sympy also solve the results of complex, the truth is I only need the results of REAL. So, may I ask how to make sympy only solve the result in the REAL domain or should I use other module to solve these equations?
This the code.
from sympy import *
from sympy.solvers.solveset import nonlinsolve
h_0 = 170
b = 120
Es = 205
h = 200
M = 19760400
fc = 83
fy = 585
def cal(para):
Ec_f, As_f, ft_f = para
vp_c, vp_s, x_n = symbols('vp_c, vp_s, x_n', real=True)
f1 = vp_c / vp_s - x_n / (h_0 - x_n)
f2 = 1 / 2 * Ec_f * vp_c * b * x_n - As_f * Es * vp_s - ft_f * b * (h - x_n)
f3 = M - As_f * Es * vp_s * (h_0 - x_n / 3) - ft_f * b * (h - x_n) * (h / 2 + x_n / 6)
re = nonlinsolve([f1, f2, f3], [vp_c, vp_s, x_n])
return re
para = [42.4, 226, 3]
result = cal(para)
The code above need about 20 seconds on my laptop with i5-5500U. Because I need a lot of loop, so it is important to speed up the sympy.
And these is the result of the first loop.
{(-0.469378305833599, 1.02614290514871, -143.317861965125), (1.00656308634739, 2.01548035330581, 56.6225231688573), ((-183.969547582998 - 351.920528939668*I)*(0.00608328163162871 - 0.00630805832877277*I + 4.48116677633078e-8*(-183.969547582998 - 351.920528939668*I)**2)/(2.44289841241567 + 1.15340253748558e-5*(-183.969547582998 - 351.920528939668*I)**2 + 2.76016101129151*I), -0.429603644119307*(-1.36072460310392 + 0.690040252822878*I)*(1.03415787737688 - 1.07236991589137*I + 7.61798351976232e-6*(-183.969547582998 - 351.920528939668*I)**2), -183.969547582998 - 351.920528939668*I), ((-183.969547582998 + 351.920528939668*I)*(0.00608328163162871 + 4.48116677633078e-8*(-183.969547582998 + 351.920528939668*I)**2 + 0.00630805832877277*I)/(2.44289841241567 - 2.76016101129151*I + 1.15340253748558e-5*(-183.969547582998 + 351.920528939668*I)**2), -0.429603644119307*(-1.36072460310392 - 0.690040252822878*I)*(1.03415787737688 + 7.61798351976232e-6*(-183.969547582998 + 351.920528939668*I)**2 + 1.07236991589137*I), -183.969547582998 + 351.920528939668*I)}