Search code examples
matlabfunctionvectorvectorizationevaluate

Evaluating hypergeometric function with a vector in Matlab


I am using the generalized hypergeometric function in Matlab by calling hypergeom(a,b,z).

This function produces for a = 1 and a = 2, b = 2 and z = 5:

>>hypergeom(1,2,5)
29.4826318205153

>>hypergeom(2,2,5)
148.413159102577

Now, I want to evaluate the hypergeometric over a vector of a values. So if I enter hypergeom(1:2,2,5) I would expect the output:

[29.4826318205153, 148.413159102577]

However, when I enter this in Matlab I get:

>>hypergeom(1:2,2,5)
-0.25

So a single value is returned, for a vector of input values for a. How do I correctly call hypergeom in Matlab so that I get the same lenght of the output vector as the length of the input vector of a?

EDIT: In this specific calculation I am evaluating the so-called Confluent hypergeometric function (solution to Kummer's differential equation, see: https://en.wikipedia.org/wiki/Confluent_hypergeometric_function). This is the 1F1 function. This means that length(N) = 1 and length(D) = 1.

The standard built-in function hypergeom is the generalized hypergeometric function, which does not allow the computation of hypergeom(1:2,2,5) in the way I want it.

Patrick Mousaw uploaded his Matlab code for the confluent hypergeometric function(https://nl.mathworks.com/matlabcentral/fileexchange/29766-confluent-hypergeometric-function), which is the version of the hypergeometric function I am using. A slight adaptation to his code, allowing for elementwise multiplication, returns exactly what I want. :)


Solution

  • In this specific calculation I am evaluating the so-called Confluent hypergeometric function (solution to Kummer's differential equation, see: https://en.wikipedia.org/wiki/Confluent_hypergeometric_function). This is the 1F1 function. This means that length(N) = 1 and length(D) = 1.

    The standard built-in function hypergeom is the generalized hypergeometric function, which does not allow the computation of hypergeom(1:2,2,5) in the way I want it.

    Patrick Mousaw uploaded his Matlab code for the confluent hypergeometric function(https://nl.mathworks.com/matlabcentral/fileexchange/29766-confluent-hypergeometric-function), which is the version of the hypergeometric function I am using. A slight adaptation to his code, allowing for elementwise multiplication, returns exactly what I want. :)