2014-02-21 44 views
3

我試圖解決分貝以下等式(爲簡單起見,我說分貝如問題標題X):解決對於x高度非線性方程在Python

image of equation

所有的等式中的其他項是已知的。我嘗試使用SymPy來象徵性地解決dB問題,但我一直在獲取超時錯誤。我也嘗試使用scipy.optimize中的fminbound,但dB的答案是錯誤的(請參閱下面的Python代碼,使用fminbound方法)。

有誰知道用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 
+0

聽起來像一個沃爾夫林阿爾法工作http://www.wolframalpha.com/input/?i=%28x+-+0.32%29^0.8*%28x+%2B+1.45%29^1.1+%3D+exp %280.8%29 – deinonychusaur

+0

這是否有幫助(1d在scipy中的根發現):http://stackoverflow.com/questions/21720489/how-to-solve-an-1-parameter-equation-using-python-scipy-numpy/21726156#21726156 –

+0

@alexandreiolov您在鏈接中指出的建議可能是正確的做法。你能發表更多細節的答案嗎? – wigging

回答

0

下面是四個單暗淡根的方法:

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) 

另外牛頓 - 拉夫遜(割線/海利)方法:

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

的SciPy的文檔建議brentq如果有一個包圍間隔。

+0

謝謝。所有的方法似乎工作正常,並給出類似的答案。我還發現'scipy.optimize'的'fsolve'方法起作用。 – wigging

+0

是的,fsolve可能會(當然)工作,但它是一個多維的根檢索器,這增加了開銷(或不,我不知道,也許它相當於'牛頓'一維根檢索器 –

0

要解決什麼在你的標題很簡單:

In [9]: 

import numpy as np 

import scipy.optimize as so 

In [10]: 

def f(x): 

    return ((x-0.32)**0.8+(x+1.45)**1.1-np.exp(0.8))**2 

In [11]: 

so.fmin(f, x0=5) 

Optimization terminated successfully. 
     Current function value: 0.000000 
     Iterations: 20 
     Function evaluations: 40 

Out[11]: 

array([ 0.45172119]) 

In [12]: 

f(0.45172119) 

Out[12]: 

4.7663411535618792e-13 

所有其它參數不變?

+0

標題中的等式用作示例。我試圖解決的實際方程式在上面貼出的圖像中。請參閱我發佈的代碼以獲取更多信息。 – wigging

+1

@Gavin:標題不是隨機的例子,他們要解釋這個問題的主題。 – DSM

+0

@DSM瞭解。我不想把整個公式放在標題中,所以我給出了主要公式的一般形式。 – wigging