numpy函数给出不正确的结果-手动和excel检查

numpy函数给出不正确的结果-手动和excel检查,numpy,math,geo,Numpy,Math,Geo,我正在用numpy为岩石物理建模编写一些函数,并注意到我的一个函数给出了错误的结果。该函数是我对Hertz Mindlin球体建模的实现: 以下是我目前的功能: # Hertz-Mindlin sphere pack model: import numpy as np def hertzmindlin(K0, G0, PHIC, P, f=1.0): ''' Hertz-Mindlin sphere-pack model, adapted from: 'Dvorkin, J. and

我正在用numpy为岩石物理建模编写一些函数,并注意到我的一个函数给出了错误的结果。该函数是我对Hertz Mindlin球体建模的实现:

以下是我目前的功能:

# Hertz-Mindlin sphere pack model: 

import numpy as np 

def hertzmindlin(K0, G0, PHIC, P, f=1.0):
'''
Hertz-Mindlin sphere-pack model, adapted from:
'Dvorkin, J. and Nur, A., 1996. Elasticity of high-porosity sandstones: 
Theory for two North Sea data sets. Geophysics, 61(5), pp.1363-1370."

Arguments:
K0 = Bulk modulus of mineral in GPa
G0 = Shear modulus of mineral in GPa
PHIC = Critical porosity for mineral-fluid mixture. Calculate using Dvorkin-Nuir (1995) or use literature
P = Confining pressure in GPa
f = Shear modulus correction factor. Default = 1

Results:
V0 = Theoretical poissons ratio of mineral
n = Coordination number of sphere-pack, calculated from Murphy's (1982) empirical relation
K_HM = Hertz-Mindlin effective dry Bulk modulus at pressure, P, in GPa
G_HM = Hertz-Mindlin effective dry Shear modulus at pressure, P, in GPa

'''
V0 = (3*K0-2*G0)/(6*K0+2*G0) # Calculated theoretical poissons ratio of bulk rock
n = 20-(34*PHIC)+(14*(PHIC**2)) # Coordination number at critical porosity (Murphy 1982)
K_HM = (P*(n**2*(1-PHIC)**2*G0**2) / (18*np.pi**2*(1-V0)**2))**(1/3)
G_HM = ((2+3*f-V0*(1+3*f))/(5*(2-V0))) * ((P*(3*n**2*(1-PHIC)**2*G0**2)/(2*np.pi**2*(1-V0)**2)))**(1/3)
return K_HM, G_HM
问题是,当我为以下输入运行此函数时:

K、 G,=36,45

PHIC=0.4

p=0.001

我得到的结果是K_HM=1.0,G_HM=0.49009

手工计算和excel计算的值显示这是不正确的,我应该输出K_HM=0.763265313,G_HM=1.081083984

基于输入K,G,输出G应该大于K这一事实,我相当确定函数中出现了一些错误(当前较小)


任何帮助都将不胜感激!我可以在excel中执行此操作,但理想情况下,我希望所有操作都在python中运行

在Python2中,整数除法(使用
/
)返回一个整数。例如,
1/3=0
。 在Python3中,整数的除法(使用
/
)可能返回浮点

看起来您正在使用Python2。要获得浮点除法(在Python2和Python3中),请确保每个除法操作至少包含一个浮点:例如,将
1/3
更改为
1.0/3
1/3.0
或(可接受但可读性较差,
1/3.
):


或者,在Python2的更高版本(例如Python2.7)中,您可以放置

from __future__ import division

在脚本顶部(在所有其他导入语句之前)添加到。

Awesome!我想这可能与数字格式有关。不幸的是,我无法改变我的Python版本或环境,但将来会考虑这个问题!
from __future__ import division