【问题标题】:Plot with variable limit of integration in python在python中具有可变积分限制的绘图
【发布时间】: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


    【解决方案1】:
    [integrate.quad(H, 0, t)[0] for t in y]
    

    quads 的输入是f, a, b,在这里您可以对y 中的所有t 进行从0t 的集成。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-28
      • 2020-08-23
      • 1970-01-01
      • 2021-02-21
      • 2014-03-31
      • 2019-10-25
      • 2021-12-22
      • 2012-11-27
      相关资源
      最近更新 更多