冲击波跳跃条件
shock wave jump conditions
from scipy.optimize import fsolve
x1=input("P1")
y1=input("rho1")
v1=input("velocity1")
def eqn(x): #three jump condition equations
f1=(x[1]*x[2])-(y1*v1)
f2=x[0]+(0.5*(y1**2)*(v1**2)/x[1])-x1-(0.5*y1*v1*v1)
f3=(0.5*(y1**2)*(v1**2)/(x[1]**2))+(2.5*(x[0]/x[1]))-(0.5*v1*v1)-(2.5*(x1/y1))
return(f1,f2,f3)
y=[10,11,12] #initial guess
print fsolve(eqn,y)
`我必须求解三个非线性方程组,也称为冲击波中的跳跃条件。我被要求使用 scipy.optimize 这样做,我们采用三个已知参数并使用它们找到其余三个参数。
但是我没有得到正确的结果,它根据初始猜测值变化很大。
Following are the relations. I am taking the value of P1, rho1 and V1 from the user and trying the find out the rest three
除了 Python 特定的小细节外,您的方程式似乎是正确的。解决方案非常简单:将所有输入转换为 floats.
x1=float(input("P1"))
y1=float(input("rho1"))
v1=float(input("velocity1"))
问题是 f3
表达式中的 x1/y1
是用 整数除法 (截断结果)而不是 浮点除法.
这意味着您可能使用整数值进行了测试。为原始代码提供浮点格式输入(例如 5.0, 14.0, 3.0
)也按预期工作。
from scipy.optimize import fsolve
x1=input("P1")
y1=input("rho1")
v1=input("velocity1")
def eqn(x): #three jump condition equations
f1=(x[1]*x[2])-(y1*v1)
f2=x[0]+(0.5*(y1**2)*(v1**2)/x[1])-x1-(0.5*y1*v1*v1)
f3=(0.5*(y1**2)*(v1**2)/(x[1]**2))+(2.5*(x[0]/x[1]))-(0.5*v1*v1)-(2.5*(x1/y1))
return(f1,f2,f3)
y=[10,11,12] #initial guess
print fsolve(eqn,y)
`我必须求解三个非线性方程组,也称为冲击波中的跳跃条件。我被要求使用 scipy.optimize 这样做,我们采用三个已知参数并使用它们找到其余三个参数。 但是我没有得到正确的结果,它根据初始猜测值变化很大。
Following are the relations. I am taking the value of P1, rho1 and V1 from the user and trying the find out the rest three
除了 Python 特定的小细节外,您的方程式似乎是正确的。解决方案非常简单:将所有输入转换为 floats.
x1=float(input("P1"))
y1=float(input("rho1"))
v1=float(input("velocity1"))
问题是 f3
表达式中的 x1/y1
是用 整数除法 (截断结果)而不是 浮点除法.
这意味着您可能使用整数值进行了测试。为原始代码提供浮点格式输入(例如 5.0, 14.0, 3.0
)也按预期工作。