与数组的递归积分 - Stefan Boltzmann定律

时间:2017-12-18 17:19:20

标签: numpy matplotlib scipy

我试图通过整合普朗克定律绘制Stefan Boltzmann定律。当我设置一个温度,比如说T = 3000时,代码可以很好地产生它的积分。但是,当我将T作为像np.array([310,3000,5800,15000])这样的数组时,代码会给我错误。附图是我试图重现的情节。任何有解决这个问题的见解的人都会非常感激。提前谢谢。

import matplotlib.pyplot as plt
import numpy as np

h = 6.626e-34
c = 2.9979e+8
k = 1.38e-23
T=np.array([310,3000,5800,15000])

from scipy.integrate import quad
def integrand(wav):
    return (2.0*3.14*h*c**2)/ ( ((wav*1e3*1e-9)**5) * (np.exp(h*c/(wav*1e3*1e-9*k*T)) - 1.0) )*1e-6

power, err = quad(integrand, 0.01, 100)
print(power)

Stefan Boltzmann law by Methamatica

1 个答案:

答案 0 :(得分:1)

您需要分别对每个温度进行积分。

import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import quad

h = 6.626e-34
c = 2.9979e+8
k = 1.38e-23
temps=np.linspace(300,15000)


def integrand(wav,T):
    return (2.0*3.14*h*c**2)/ ( ((wav*1e3*1e-9)**5) * (np.exp(h*c/(wav*1e3*1e-9*k*T)) - 1.0) )*1e-6

p = lambda T: quad(integrand, 0.1, 100, args=(T,))[0]

powers = list(map(p, temps))
plt.plot(temps, powers)
plt.xlabel("Temperature [K]")
plt.ylabel("Power")

plt.show()

enter image description here