在Python中求解x的高度非线性方程 [英] Solve highly non-linear equation for x in Python

查看:166
本文介绍了在Python中求解x的高度非线性方程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to solve the following equation for dB (for simplicity, I stated dB as x in the question title):

等式中的所有其他术语都是已知的.我尝试使用SymPy来象征性地解决dB,但我不断遇到超时错误.我也尝试过使用scipy.optimize中的fminbound,但是dB的答案是错误的(请参见下面的使用fminbound方法的Python代码).

All of the other terms in the equation are known. I tried using SymPy to symbolically solve for dB but I kept getting time out errors. I also tried using fminbound from scipy.optimize but the answer for dB is wrong (see below for Python code using the fminbound approach).

有人知道使用Python解决dB方程的方法吗?

Does anyone know of a way to solve the equation for dB using Python?

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

推荐答案

以下是四种单调根方法:

Here are the four single-dim root-methods:

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)

还有牛顿-拉普森(割线/海利)方法:

Also the newton-raphson (secant / haley) method:

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

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

The scipy documentation recommends brentq if you have a bracketing interval.

这篇关于在Python中求解x的高度非线性方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆