python - 在 Python 中求解 x 的高度非线性方程

标签 python python-3.x numpy scipy sympy

我正在尝试求解以下 dB 等式(为简单起见,我在问题标题中将 dB 表示为 x):

image of equation

等式中的所有其他项都是已知的。我尝试使用 SymPy 来象征性地求解 dB,但我一直收到超时错误。我还尝试使用 scipy.optimize 中的 fminbound 但 dB 的答案是错误的(请参阅下面使用 fminbound 方法的 Python 代码)。

有谁知道使用 Python 求解 dB 方程的方法吗?

import numpy as np

from scipy.optimize import fminbound

#------------------------------------------------------------------------------
# parameters

umf = 0.063         # minimum fluidization velocity, m/s
dbed = 0.055        # bed diameter, m
z0 = 0              # position bubbles are generated, m
z = 0.117           # bed vertical position, m
g = 9.81            # gravity, m/s^2

#------------------------------------------------------------------------------
# calculations

m = 3                       # multiplier for Umf
u = m*umf                   # gas superficial velocity, m/s

abed = (np.pi*dbed**2)/4.0  # bed cross-sectional area, m^2

# calculate parameters used in equation

dbmax = 2.59*(g**-0.2)*(abed*(u-umf))**0.4
dbmin = 3.77*(u-umf)**2/g

c1 = 2.56*10**-2*((dbed / g)**0.5/umf)

c2 = (c1**2 + (4*dbmax)/dbed)**0.5

c3 = 0.25*dbed*(c1 + c2)**2

dbeq = 0.25*dbed*(-c1 + (c1**2 + 4*(dbmax/dbed))**0.5 )**2

# general form of equation ... (term1)^power1 * (term2)^power2 = term3

power1 = 1 - c1/c2

power2 = 1 + c1/c2

term3 = np.exp(-0.3*(z - z0)/dbed)

def dB(d):
    term1 = (np.sqrt(d) - np.sqrt(dbeq)) / (np.sqrt(dbmin) - np.sqrt(dbeq))
    term2 = (np.sqrt(d) + np.sqrt(c3)) / (np.sqrt(dbmin) + np.sqrt(c3))
    return term1**power1 * term2**power2 - term3

# solve main equation for dB

dbub = fminbound(dB, 0.01, dbed)

print 'dbub = ', dbub

最佳答案

这里有四种单维根方法:

from scipy.optimize import brentq, brenth, ridder, bisect
for rootMth in [brentq, brenth, ridder, bisect]:
    dbub = rootMth(dB, 0.01, dbed)
    print 'dbub = ', dbub, '; sanity check (is it a root?):', dB(dbub)

还有 newton-raphson(正割/haley)方法:

from scipy.optimize import newton
dbub = newton(dB, dbed)
print 'dbub = ', dbub, '; sanity check (is it a root?):', dB(dbub)

如果您有包围间隔,scipy 文档建议使用 brentq。

关于python - 在 Python 中求解 x 的高度非线性方程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21937643/

相关文章:

python - 如何确认我的 shebang 线适用于 python?

Python 类型检查

python - 将特定权重乘以列并在新列中加在一起

python - 关闭连接Socket抛出 'Invalid syntax with except IOError'

arrays - 科学/ NumPy : summation over multiple indices

python - 将 MySQL 表数据转储到 csv 并转换字符编码的最佳方法是什么?

python - 用不同名称的pyenv设置两个不同的python版本?

python - 插入字节类型的对象

python - python 中的期望值

python - 在对每个数组进行更改时迭代数组列表