#!/usr/bin/perl # Varun Bhalerao # http://www.astro.caltech.edu/~varun/ay20/ps2/photons_sun.pl # Count the number of photons from a blackbody in a given band # # ********** # CGS units ! # ********** $h=6.63e-27; $c=2.998e10; $k=1.38e-16; $t=5777; $hckt=$h*$c/$k/$t; $step=1000; #step size as a fraction of wavelength, 1/$step = dlambda / lambda sub count(){ ($lstart,$lend)=@_; print "Wavelength band: $lstart nm - $lend nm. "; $lstart*=1e-7; #convert nm into cm $lend*=1e-7; #convert nm into cm $dlambda=$lstart/$step; $lambda=$lstart; my $integral=0; while ($lambda<$lend){ $dlambda=$lambda/$step; #it is important that step size varies with the wavelength ! $lambda+=$dlambda; $bldl=2*$c/$lambda**4/ (exp($hckt/$lambda) -1) *$dlambda; $integral+=$bldl; } printf("Number of Photons %E\n", $integral); } &count(300,1100); &count(505,595); &count(391,489); &count(331,399); &count(0.519,519000);#peak emission for 5777K is 519 nm. integrate from 519/1000 to 519*1000