【发布时间】:2020-11-29 15:10:06
【问题描述】:
我有函数 f(x),我想将函数从 0 积分到某个点 x 在区间 (0,2) 中。我知道如何在mathematica中解决这个问题,但是我不知道如何在python中解决这个问题。
数学
OM=0.3
OL=0.7
f[x_] := ((1 + x)^3 OM + OL)^(-1/2);
Plot[NIntegrate[f[x], {x, 0, z2}], {z2, 0, 2}]
我在 python 中的代码:
import numpy as np
import matplotlib.pyplot as plt
from scipy import integrate
y = np.linspace(0, 2, 20)
Om=0.3
Ol=1-Om
def H(x):
return (Om*(1+x)**3 +Ol)**(-1./2)
#Integral from a single point in the inverval
print quad(H,0,2)
我怎样才能在 python 中做同样的事情?
【问题讨论】:
标签: python python-2.7 numerical-integration