ellpef.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* ellpef.c
  2. *
  3. * Complete elliptic integral of the second kind
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * float m1, y, ellpef();
  10. *
  11. * y = ellpef( m1 );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Approximates the integral
  18. *
  19. *
  20. * pi/2
  21. * -
  22. * | | 2
  23. * E(m) = | sqrt( 1 - m sin t ) dt
  24. * | |
  25. * -
  26. * 0
  27. *
  28. * Where m = 1 - m1, using the approximation
  29. *
  30. * P(x) - x log x Q(x).
  31. *
  32. * Though there are no singularities, the argument m1 is used
  33. * rather than m for compatibility with ellpk().
  34. *
  35. * E(1) = 1; E(0) = pi/2.
  36. *
  37. *
  38. * ACCURACY:
  39. *
  40. * Relative error:
  41. * arithmetic domain # trials peak rms
  42. * IEEE 0, 1 30000 1.1e-7 3.9e-8
  43. *
  44. *
  45. * ERROR MESSAGES:
  46. *
  47. * message condition value returned
  48. * ellpef domain x<0, x>1 0.0
  49. *
  50. */
  51. /* ellpe.c */
  52. /* Elliptic integral of second kind */
  53. /*
  54. Cephes Math Library, Release 2.1: February, 1989
  55. Copyright 1984, 1987, 1989 by Stephen L. Moshier
  56. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  57. */
  58. #include <math.h>
  59. static float P[] = {
  60. 1.53552577301013293365E-4,
  61. 2.50888492163602060990E-3,
  62. 8.68786816565889628429E-3,
  63. 1.07350949056076193403E-2,
  64. 7.77395492516787092951E-3,
  65. 7.58395289413514708519E-3,
  66. 1.15688436810574127319E-2,
  67. 2.18317996015557253103E-2,
  68. 5.68051945617860553470E-2,
  69. 4.43147180560990850618E-1,
  70. 1.00000000000000000299E0
  71. };
  72. static float Q[] = {
  73. 3.27954898576485872656E-5,
  74. 1.00962792679356715133E-3,
  75. 6.50609489976927491433E-3,
  76. 1.68862163993311317300E-2,
  77. 2.61769742454493659583E-2,
  78. 3.34833904888224918614E-2,
  79. 4.27180926518931511717E-2,
  80. 5.85936634471101055642E-2,
  81. 9.37499997197644278445E-2,
  82. 2.49999999999888314361E-1
  83. };
  84. float polevlf(float, float *, int), logf(float);
  85. float ellpef( float xx)
  86. {
  87. float x;
  88. x = xx;
  89. if( (x <= 0.0) || (x > 1.0) )
  90. {
  91. if( x == 0.0 )
  92. return( 1.0 );
  93. mtherr( "ellpef", DOMAIN );
  94. return( 0.0 );
  95. }
  96. return( polevlf(x,P,10) - logf(x) * (x * polevlf(x,Q,9)) );
  97. }