-
Notifications
You must be signed in to change notification settings - Fork 0
/
blackbody.py
40 lines (34 loc) · 915 Bytes
/
blackbody.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import math
import numpy
from decimal import *
import matplotlib.pyplot as plt
global h, k, c, b
h = Decimal(6.6260695729e-34)
k = Decimal(1.380648813e-23)
c = Decimal(2.99792458e8)
b = Decimal(2.8977685e-3)
def bbfunction(temp):
def f(lam):
numer = 2*h*(c**2)
expo = h*c/(lam*k*temp)
denom = (lam**4)*((Decimal(math.e)**expo)-1)
return numer/denom
return f
def blackbody(temp):
maxlam = b/temp
center = round(math.log(maxlam, 10))
x = numpy.arange(center-2, center+5, .01)
x = map(lambda u: Decimal(10**u), x)
y = map(bbfunction(temp), x)
x = map(lambda u: u*Decimal(1e6), x)
plt.loglog(x, y)
plt.xlabel('lambda (microns)')
plt.ylabel('F*lambda')
plt.ylim(ymin=1e-16)
plt.show()
while True:
temp = raw_input("Enter temperature: ")
if temp == "exit":
break
temp = Decimal(temp)
blackbody(temp)