解决隐含函数

时间:2018-02-17 14:53:18

标签: python scipy solver

我有一个隐含的函数要解决:

enter image description here

所以我尝试从scipy.optimize:

查找根函数
- fsolve : RuntimeWarning: The iteration is not making good progress, as 
  measured by the improvement from the last ten iterations.
- excitingmixing : NoConvergence
-brent:  RuntimeWarning: invalid value encountered in double_scalars (but 
  without a chance to set constraints)

我必须承认我不确定正确的求解器。有人可以帮忙吗?

最小的工作示例:

from scipy.optimize import fsolve, newton, brent, excitingmixing
import numpy as np

def func_zeta(zeta):
    k= 1.2
    Re = 5000.
    d = 0.03
    return (2.51 /Re/np.sqrt(zeta)+k/d/3.71) + 10**(0.5/ np.sqrt(zeta))
zeta = fsolve(func_zeta, 64/Re)

1 个答案:

答案 0 :(得分:1)

您的公式翻译存在问题。它不应该是以下return声明吗?

return 2.51 / (Re * np.sqrt(zeta)) + k / (d * 3.71) - 10 ** (-0.5 / np.sqrt(zeta))

但即便如此,我们再次获得RuntimeWarning。让我们再试一次并替换zeta

from scipy.optimize import fsolve
import numpy as np

def zeta_in_disguise(x):
    global k, d, Re
    return x + 2 * np.log10(2.51 * x / Re + k / (d * 3.71))

k = 1.2
Re = 5000
d = 0.03
#x = 1 / np.sqrt(zeta)
x = fsolve(zeta_in_disguise, 0)
print(x)
#let's test, if x is really the solution to the equation
print(-2 * np.log10(2.51 * x / Re + k / d / 3.71))

啊,现在它收敛并产生以下输出

-2.06528864

我们遇到了问题 - 当我们只考虑浮点数时,你的给定参数没有解决方案,至少没有。