Browse Source

Special Functions: document the n-parameter of the exponential integral

cuda
Christoph Ruegg 12 years ago
parent
commit
53a464c86c
  1. 16
      src/Numerics/SpecialFunctions/ExponentialIntegral.cs

16
src/Numerics/SpecialFunctions/ExponentialIntegral.cs

@ -41,9 +41,10 @@ namespace MathNet.Numerics
public static partial class SpecialFunctions public static partial class SpecialFunctions
{ {
/// <summary> /// <summary>
/// Computes the Exponential Integral function. /// Computes the generalized Exponential Integral function (En).
/// </summary> /// </summary>
/// <param name="x">The argument of the Exponential Integral function.</param> /// <param name="x">The argument of the Exponential Integral function.</param>
/// <param name="n">Integer power of the denominator term. Generalization index.</param>
/// <returns>The value of the Exponential Integral function.</returns> /// <returns>The value of the Exponential Integral function.</returns>
/// <remarks> /// <remarks>
/// <para>This implementation of the computation of the Exponential Integral function follows the derivation in /// <para>This implementation of the computation of the Exponential Integral function follows the derivation in
@ -70,7 +71,7 @@ namespace MathNet.Numerics
int maxIterations = 100; int maxIterations = 100;
int i, ii; int i, ii;
double ndbl = (double)n; double ndbl = (double)n;
double result = double.NaN; double result;
double nearDoubleMin = 1e-100; //needs a very small value that is not quite as small as the lowest value double can take double nearDoubleMin = 1e-100; //needs a very small value that is not quite as small as the lowest value double can take
double factorial = 1.0d; double factorial = 1.0d;
double del; double del;
@ -80,13 +81,11 @@ namespace MathNet.Numerics
//special cases //special cases
if (n == 0) if (n == 0)
{ {
result = Math.Exp(-1.0d*x)/x; return Math.Exp(-1.0d*x)/x;
return result;
} }
else if (x == 0.0d) else if (x == 0.0d)
{ {
result = 1.0d/(ndbl - 1.0d); return 1.0d/(ndbl - 1.0d);
return result;
} }
//general cases //general cases
//continued fraction for large x //continued fraction for large x
@ -106,13 +105,12 @@ namespace MathNet.Numerics
h = h*del; h = h*del;
if (Math.Abs(del - 1.0d) < epsilon) if (Math.Abs(del - 1.0d) < epsilon)
{ {
result = h*Math.Exp(-x); return h*Math.Exp(-x);
return result;
} }
} }
throw new ArithmeticException(string.Format("continued fraction failed to converge for x={0}, n={1})", x, n)); throw new ArithmeticException(string.Format("continued fraction failed to converge for x={0}, n={1})", x, n));
} }
//series computation for small x //series computation for small x
else else
{ {
result = ((ndbl - 1.0d) != 0 ? 1.0/(ndbl - 1.0d) : (-1.0d*Math.Log(x) - Constants.EulerMascheroni)); //Set first term. result = ((ndbl - 1.0d) != 0 ? 1.0/(ndbl - 1.0d) : (-1.0d*Math.Log(x) - Constants.EulerMascheroni)); //Set first term.

Loading…
Cancel
Save