Calculate the definite integral of $\int_0^5 a x^3 dx$ for a given value of a and compare it with the analytic answer: $y=\frac{a}{4} 5^4$


In [0]:
xvec=arange(0,5,0.01) #vector from 0 to 5 in 0.01 step sizes

In [0]:
xvec[:10] #print the first 10 values

Now make a vector of intervals $dx$ using the diff function


In [0]:
dx=diff(xvec) #note that dx is one item shorter than xvec

integration is just the sum over rectangles of width $dx$ and height $ax^3$


In [0]:
a=5
integral=sum(a*xvec[0:-1]**3.*dx)
analytic=a/4.*5.**4.
print "analytic: %8.4f, approximate: %8.4f" % (analytic,integral)

Now apply this to the Planck function (Stull Chapter 2, Equation 2.13, p. 36):

$E_\lambda^* = \frac{c1}{\lambda^5 \left ( exp(c_2/(\lambda T)) - 1 \right )}$

or Planck's law

$E_\lambda* =\pi \frac{2 hc^2}{\lambda^5}\frac{1}{ e^{\frac{hc}{\lambda kT}}-1}$

where

$h$=Planck's constant ($6.63 \times 10^{-34}$ Joule seconds})

$c$= Speed of light in a vacuum ($3.00 \times 10^{8}\ \mathrm{meters/second}$)

$k_b$ =Boltzman's constant ($1.38 \times 10^{-23}\ \mathrm{Joules/Kelvin}$)

(note that $E_\lambda*$ is the blackbody flux, or irradiance, with units of $W/m^2 /\mu m$) Wikipedia (and Wallace and Hobbs) give the blackbody radiance which differs by by a factor of $\pi$ and has units of $W/m^2/\mu m /sr$. We will talk a lot about this in the next few weeks, don't worry about it for now.


In [0]:
c=2.99792458e+08  #m/s -- speed of light in vacumn
h=6.62606876e-34  #J s  -- Planck's constant
kb=1.3806503e-23  # J/K  -- Boltzman's constant

def planckwavelen(wavel,Temp):
    """input wavelength in microns and Temp in K, output
    bbr in W/m^2/micron
    """
    wavel=wavel*1.e-6  #convert to meters
    c1=2.*h*c**2.
    c2=h*c/kb
    Elambda=1.e-6*pi*c1/(wavel**5.*(np.exp(c2/(wavel*Temp)) -1))
    return Elambda

In [0]:
the_wavelengths=linspace(0.1,50,5000) #microns
the_temp=300 #K
flux=planckwavelen(the_wavelengths,the_temp)
plot(the_wavelengths,flux)

Assignment: Use sum and diff along with the function planckwavelen to integrate the Planck function over wavelength and verify the Stefan-Boltzman equation on Stull chapter 2 p. 37:

$E^* = \int_0^\infty E_\lambda^* d\lambda = \sigma T^4$

where $\sigma=5.67 \times 10^-8$ $W/m^2/K^{4}$

Write a set of python instructions that integrates the planck function and show that your integral agrees with the Stefan-Boltzman equation


In [0]: