求解隐函数
Solve an implicit function
我有一个隐式函数要解决:
所以我尝试了 scipy.optimize:
的 root 查找函数
- 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)
你的公式翻译有问题。不应该是下面的 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
我们遇到了问题 - 当我们只考虑浮点数时,您给定的参数没有解决方案,至少没有。
我有一个隐式函数要解决:
所以我尝试了 scipy.optimize:
的 root 查找函数- 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)
你的公式翻译有问题。不应该是下面的 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
我们遇到了问题 - 当我们只考虑浮点数时,您给定的参数没有解决方案,至少没有。