planck.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* planck.c
  2. *
  3. * Integral of Planck's black body radiation formula
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * double lambda, T, y, plancki();
  10. *
  11. * y = plancki( lambda, T );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Evaluates the definite integral, from wavelength 0 to lambda,
  18. * of Planck's radiation formula
  19. * -5
  20. * c1 lambda
  21. * E = ------------------
  22. * c2/(lambda T)
  23. * e - 1
  24. *
  25. * Physical constants c1 = 3.7417749e-16 and c2 = 0.01438769 are built in
  26. * to the function program. They are scaled to provide a result
  27. * in watts per square meter. Argument T represents temperature in degrees
  28. * Kelvin; lambda is wavelength in meters.
  29. *
  30. * The integral is expressed in closed form, in terms of polylogarithms
  31. * (see polylog.c).
  32. *
  33. * The total area under the curve is
  34. * (-1/8) (42 zeta(4) - 12 pi^2 zeta(2) + pi^4 ) c1 (T/c2)^4
  35. * = (pi^4 / 15) c1 (T/c2)^4
  36. * = 5.6705032e-8 T^4
  37. * where sigma = 5.6705032e-8 W m^2 K^-4 is the Stefan-Boltzmann constant.
  38. *
  39. *
  40. * ACCURACY:
  41. *
  42. * The left tail of the function experiences some relative error
  43. * amplification in computing the dominant term exp(-c2/(lambda T)).
  44. * For the right-hand tail see planckc, below.
  45. *
  46. * Relative error.
  47. * The domain refers to lambda T / c2.
  48. * arithmetic domain # trials peak rms
  49. * IEEE 0.1, 10 50000 7.1e-15 5.4e-16
  50. *
  51. */
  52. /*
  53. Cephes Math Library Release 2.8: July, 1999
  54. Copyright 1999 by Stephen L. Moshier
  55. */
  56. #include <math.h>
  57. #ifdef ANSIPROT
  58. extern double polylog (int, double);
  59. extern double exp (double);
  60. extern double log1p (double); /* log(1+x) */
  61. extern double expm1 (double); /* exp(x) - 1 */
  62. double planckc(double, double);
  63. double plancki(double, double);
  64. #else
  65. double polylog(), exp(), log1p(), expm1();
  66. double planckc(), plancki();
  67. #endif
  68. /* NIST value (1999): 2 pi h c^2 = 3.741 7749(22) �× 10-16 W m2 */
  69. double planck_c1 = 3.7417749e-16;
  70. /* NIST value (1999): h c / k = 0.014 387 69 m K */
  71. double planck_c2 = 0.01438769;
  72. double
  73. plancki(w, T)
  74. double w, T;
  75. {
  76. double b, h, y, bw;
  77. b = T / planck_c2;
  78. bw = b * w;
  79. if (bw > 0.59375)
  80. {
  81. y = b * b;
  82. h = y * y;
  83. /* Right tail. */
  84. y = planckc (w, T);
  85. /* pi^4 / 15 */
  86. y = 6.493939402266829149096 * planck_c1 * h - y;
  87. return y;
  88. }
  89. h = exp(-planck_c2/(w*T));
  90. y = 6. * polylog (4, h) * bw;
  91. y = (y + 6. * polylog (3, h)) * bw;
  92. y = (y + 3. * polylog (2, h)) * bw;
  93. y = (y - log1p (-h)) * bw;
  94. h = w * w;
  95. h = h * h;
  96. y = y * (planck_c1 / h);
  97. return y;
  98. }
  99. /* planckc
  100. *
  101. * Complemented Planck radiation integral
  102. *
  103. *
  104. *
  105. * SYNOPSIS:
  106. *
  107. * double lambda, T, y, planckc();
  108. *
  109. * y = planckc( lambda, T );
  110. *
  111. *
  112. *
  113. * DESCRIPTION:
  114. *
  115. * Integral from w to infinity (area under right hand tail)
  116. * of Planck's radiation formula.
  117. *
  118. * The program for large lambda uses an asymptotic series in inverse
  119. * powers of the wavelength.
  120. *
  121. * ACCURACY:
  122. *
  123. * Relative error.
  124. * The domain refers to lambda T / c2.
  125. * arithmetic domain # trials peak rms
  126. * IEEE 0.6, 10 50000 1.1e-15 2.2e-16
  127. *
  128. */
  129. double
  130. planckc (w, T)
  131. double w;
  132. double T;
  133. {
  134. double b, d, p, u, y;
  135. b = T / planck_c2;
  136. d = b*w;
  137. if (d <= 0.59375)
  138. {
  139. y = 6.493939402266829149096 * planck_c1 * b*b*b*b;
  140. return (y - plancki(w,T));
  141. }
  142. u = 1.0/d;
  143. p = u * u;
  144. #if 0
  145. y = 236364091.*p/365866013534056632601804800000.;
  146. y = (y - 15458917./475677107995483570176000000.)*p;
  147. y = (y + 174611./123104841613737984000000.)*p;
  148. y = (y - 43867./643745871363538944000.)*p;
  149. y = ((y + 3617./1081289781411840000.)*p - 1./5928123801600.)*p;
  150. y = ((y + 691./78460462080000.)*p - 1./2075673600.)*p;
  151. y = ((((y + 1./35481600.)*p - 1.0/544320.)*p + 1.0/6720.)*p - 1./40.)*p;
  152. y = y + log(d * expm1(u));
  153. y = y - 5.*u/8. + 1./3.;
  154. #else
  155. y = -236364091.*p/45733251691757079075225600000.;
  156. y = (y + 77683./352527500984795136000000.)*p;
  157. y = (y - 174611./18465726242060697600000.)*p;
  158. y = (y + 43867./107290978560589824000.)*p;
  159. y = ((y - 3617./202741834014720000.)*p + 1./1270312243200.)*p;
  160. y = ((y - 691./19615115520000.)*p + 1./622702080.)*p;
  161. y = ((((y - 1./13305600.)*p + 1./272160.)*p - 1./5040.)*p + 1./60.)*p;
  162. y = y - 0.125*u + 1./3.;
  163. #endif
  164. y = y * planck_c1 * b / (w*w*w);
  165. return y;
  166. }
  167. /* planckd
  168. *
  169. * Planck's black body radiation formula
  170. *
  171. *
  172. *
  173. * SYNOPSIS:
  174. *
  175. * double lambda, T, y, planckd();
  176. *
  177. * y = planckd( lambda, T );
  178. *
  179. *
  180. *
  181. * DESCRIPTION:
  182. *
  183. * Evaluates Planck's radiation formula
  184. * -5
  185. * c1 lambda
  186. * E = ------------------
  187. * c2/(lambda T)
  188. * e - 1
  189. *
  190. */
  191. double
  192. planckd(w, T)
  193. double w, T;
  194. {
  195. return (planck_c2 / ((w*w*w*w*w) * (exp(planck_c2/(w*T)) - 1.0)));
  196. }
  197. /* Wavelength, w, of maximum radiation at given temperature T.
  198. c2/wT = constant
  199. Wein displacement law.
  200. */
  201. double
  202. planckw(T)
  203. double T;
  204. {
  205. return (planck_c2 / (4.96511423174427630 * T));
  206. }