0

Below code is taking forever to run and is not stopping. I guess the problem is in the last line code

from sympy import *
v_swe, alpha= symbols('v_swe alpha')
Tc=310; Th=635; r=287; M=1.5; r_t=100; W=7*1000*3600;
f=1; hours=6; stress=240e+6; sf=3; eff=1-Tc/Th
v_swc=v_swe
v_k=0.01*v_swe
v_r=0.01*v_swe
v_h=0.01*v_swe
v_dc=0.01*v_swe
v_de=0.01*v_swe
c=0.5*((v_swe/Th)**2+2*v_swe*v_swc*cos(alpha)/(Th*Tc)+(v_swc/Tc)**2)
s=v_swc/(2*Tc)+ v_dc/Tc+ v_k/Tc + v_r*log(Th/Tc)/(Th-Tc) +v_h/Th +v_swe/(2*Th)+ v_de/Th
b=c/s
beta=atan((v_swe*sin(alpha)/Th)/(v_swe*cos(alpha)/Th+v_swc/Tc))
p_max=M*r/(s*(1-b))
p_mean=M*r/(s*(sqrt(1-b**2)))
W_one_cycle=pi*v_swc*p_mean*(sqrt(1-b**2)-b)*(sin(beta)+sin(beta-alpha))/b
print(1)
eq1=Eq(W_one_cycle,W/(eff*hours*3600*f))
eq2=Eq(p_max,stress/(sf*r_t))
sol_dict=solve((eq1,eq2),(v_swe, alpha))
  • You could put print in several step that you guess may be the cause. So if that step have error, your print command wouldnt be executed. So you can have better idea where the main problem is. – Albert H M May 05 '20 at 17:40

1 Answers1

0

Yes, looking for an exact solution to a highly non-linear set of equations can take a long time or be impossible (and take a long time to figure that out). If you have an idea where there are solutions to the equations, you can get a numerical result with nsolve. The output will be a Matrix which you can just flatten to get a list of the results:

>>> from sympy import flatten, nsolve
>>> flatten(nsolve((eq1,eq2),(v_swe, alpha),(1,0)))  # (1,0) is a guess
[0.213888341211035, -1.20903173428140e-5]
smichr
  • 16,948
  • 2
  • 27
  • 34