黑体光谱的普朗克公式 [英] Plancks Formula for Blackbody spectrum

查看:238
本文介绍了黑体光谱的普朗克公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个简单的python代码,以绘制给定温度(T = 200K)下强度与波长的关系图. 到目前为止,我有这个...

I am trying to write a simple python code for a plot of intensity vs wavelength for a given temperature, T=200K. So far I have this...

import scipy as sp
import math
import matplotlib.pyplot as plt
import numpy as np
pi = np.pi
h = 6.626e-34
c = 3.0e+8
k = 1.38e-23

def planck(wav, T):
    a = 2.0*h*pi*c**2
    b = h*c/(wav*k*T)
    intensity = a/ ( (wav**5)*(math.e**b - 1.0) )
    return intensity

我不知道如何定义波长(wav),因此无法生成Plancks公式的图.任何帮助将不胜感激.

I don't know how to define wavelength(wav) and thus produce the plot of Plancks Formula. Any help would be appreciated.

推荐答案

这是一个基本情节.要使用plt.plot(x, y, fmt)进行绘制,您需要两个大小相同的数组x和y,其中x是要绘制的每个点的x坐标,y是y坐标,而fmt是描述如何绘制数字的字符串.

Here's a basic plot. To plot using plt.plot(x, y, fmt) you need two arrays x and y of the same size, where x is the x coordinate of each point to plot and y is the y coordinate, and fmt is a string describing how to plot the numbers.

因此,您要做的就是创建一个均匀间隔的波长阵列(一个名为wavelengthsnp.array).可以使用arange(start, end, spacing)完成此操作,该操作将从头到尾(不包括两端)创建一个间隔为spacing的数组.

So all you need to do is create an evenly spaced array of wavelengths (an np.array which I named wavelengths). This can be done with arange(start, end, spacing) which will create an array from start to end (not inclusive) spaced at spacing apart.

然后使用函数在数组中的每个点(将存储在另一个np.array中)计算强度,然后调用plt.plot进行绘制.请注意,numpy让您以向量化形式快速对数组进行数学运算.

Then compute the intensity using your function at each of those points in the array (which will be stored in another np.array), and then call plt.plot to plot them. Note numpy let's you do mathematical operations on arrays quickly in a vectorized form which will be computationally efficient.

import matplotlib.pyplot as plt
import numpy as np

h = 6.626e-34
c = 3.0e+8
k = 1.38e-23

def planck(wav, T):
    a = 2.0*h*c**2
    b = h*c/(wav*k*T)
    intensity = a/ ( (wav**5) * (np.exp(b) - 1.0) )
    return intensity

# generate x-axis in increments from 1nm to 3 micrometer in 1 nm increments
# starting at 1 nm to avoid wav = 0, which would result in division by zero.
wavelengths = np.arange(1e-9, 3e-6, 1e-9) 

# intensity at 4000K, 5000K, 6000K, 7000K
intensity4000 = planck(wavelengths, 4000.)
intensity5000 = planck(wavelengths, 5000.)
intensity6000 = planck(wavelengths, 6000.)
intensity7000 = planck(wavelengths, 7000.)

plt.hold(True) # doesn't erase plots on subsequent calls of plt.plot()
plt.plot(wavelengths*1e9, intensity4000, 'r-') 
# plot intensity4000 versus wavelength in nm as a red line
plt.plot(wavelengths*1e9, intensity5000, 'g-') # 5000K green line
plt.plot(wavelengths*1e9, intensity6000, 'b-') # 6000K blue line
plt.plot(wavelengths*1e9, intensity7000, 'k-') # 7000K black line

# show the plot
plt.show()

您会看到:

您可能想要清理轴标签,添加图例,在同一图上绘制多个温度下的强度图.请查阅相关的matplotlib文档.

You probably will want to clean up the axes labels, add a legend, plot the intensity at multiple temperatures on the same plot, among other things. Consult the relevant matplotlib documentation.

这篇关于黑体光谱的普朗克公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆