confluent_hypergeometric_function_of_the_first_kind.sf 553 B

123456789101112131415161718
  1. #!/usr/bin/ruby
  2. # Simple implementation of the confluent hypergeometric function of the first kind.
  3. # See also:
  4. # https://en.wikipedia.org/wiki/Confluent_hypergeometric_function
  5. # https://mathworld.wolfram.com/ConfluentHypergeometricFunctionoftheFirstKind.html
  6. func F1(a, b, z, limit=1000) {
  7. sum(0..limit, {|k|
  8. rising_factorial(a, k) / rising_factorial(b, k) * z**k / k!
  9. })
  10. }
  11. say F1(1, 1, 1) #=> 2.71828182845904523536028747...
  12. say F1(13, 23, 14) #=> 6902.70292322962697731908950...
  13. say F1(-2, 4, -3) #=> 2.95