3

我知道这里有一些类似的问题,但似乎都没有真正解决我的问题。

我的代码如下所示:

import numpy 

import matplotlib.pyplot as plt

from scipy import integrate as integrate

def H(z , omega_m , H_0 = 70):

    omega_lambda=1-omega_m
    z_prime=((1+z)**3)
    wurzel=numpy.sqrt(omega_m*z_prime + omega_lambda)

    return H_0*wurzel



def H_inv(z, omega_m , H_0=70):

    return 1/(H(z, omega_m, H_0=70))

def integral(z, omega_m , H_0=70):

    I=integrate.quad(H_inv,0,z,args=(omega_m,))
    return I


def d_L(z, omega_m , H_0=70):

    distance=(2.99*(10**8))*(1+z)*integral(z, omega_m, H_0=70)

    return distance

这些功能确实有效,我的问题:如何绘制 d_L 与 z ?就像我在 d_L 的定义中有这个积分函数显然是一个问题,它取决于 z 和一些 args=(omega_m, )。

4

2 回答 2

2

为了以@eyllanesc 的解决方案为基础,以下是绘制几个 omega 值的方法:

import numpy

import matplotlib.pyplot as plt

from scipy import integrate


def H(z, omega_m, H_0=70):
    omega_lambda = 1 - omega_m
    z_prime = ((1 + z) ** 3)
    wurzel = numpy.sqrt(omega_m * z_prime + omega_lambda)

    return H_0 * wurzel


def H_inv(z, omega_m, H_0=70):
    return 1 / (H(z, omega_m, H_0=70))


def integral(z, omega_m, H_0=70):
    I = integrate.quad(H_inv, 0, z, args=(omega_m,))[0]
    return I


def d_L(z, omega_m, H_0=70):
    distance = (2.99 * (10 ** 8)) * (1 + z) * integral(z, omega_m, H_0)
    return distance

z0 = -1.8
zf = 10
zs = numpy.linspace(z0, zf, 1000)

fig, ax = plt.subplots(nrows=1,ncols=1, figsize=(16,9))

for omega_m in np.linspace(0, 1, 10):
    d_Ls = numpy.linspace(z0, zf, 1000)
    for index in range(zs.size):
        d_Ls[index] = d_L(zs[index], omega_m=omega_m)
    ax.plot(zs,d_Ls, label='$\Omega$ = {:.2f}'.format(omega_m))
ax.legend(loc='best')
plt.show()

用多条线绘制

于 2016-12-04T18:21:02.107 回答
1

尝试我的解决方案:

import numpy

import matplotlib.pyplot as plt

from scipy import integrate


def H(z, omega_m, H_0=70):
    omega_lambda = 1 - omega_m
    z_prime = ((1 + z) ** 3)
    wurzel = numpy.sqrt(omega_m * z_prime + omega_lambda)

    return H_0 * wurzel


def H_inv(z, omega_m, H_0=70):
    return 1 / (H(z, omega_m, H_0=70))


def integral(z, omega_m, H_0=70):
    I = integrate.quad(H_inv, 0, z, args=(omega_m,))[0]
    return I


def d_L(z, omega_m, H_0=70):
    distance = (2.99 * (10 ** 8)) * (1 + z) * integral(z, omega_m, H_0)
    return distance

z0 = -1.8
zf = 10
zs = numpy.linspace(z0, zf, 1000)
d_Ls = numpy.linspace(z0, zf, 1000)
omega_m = 0.2

for index in range(zs.size):
     d_Ls[index] = d_L(zs[index], omega_m=omega_m)
plt.plot(zs,d_Ls)
plt.show()

输出:

在此处输入图像描述

于 2016-12-04T17:02:50.790 回答