Bug in MATLAB evaluation of generalized hypergeometric functions (for relatively larger arguments)

6 次查看(过去 30 天)
This concerns the evaluation of pFq generalized hypergeomtric functions at a specific point (unity).
In particular, I am concerned with the evaluation of 3F2 generalized hypergeometric functions of the type: hypergeom([2,-m,-n],[(1.5-m),(1.5-n)],1) for various positive integer values of m and n, In a program, this function is embedded in loops over m and n, both varying over 1:50 (for a preliminary illustration).
I observe that MATLAB's evaluation appears to break down for values of m and n, larger than 40. It consistently produces the answer infinity, while the answer is known to be finite (e.g. even from Wolfram Alpha evaluation of the same function).
This can be seen very simply seen from the following code snippett:
gg = inline(hypergeom([2,-39,-40],[-37.5,-38.5],y))
gg(1)
Alternatively I tried using:
vpa(gg(1))
in place of the second line.
One can likewise iterate for other values of m and n.
The following two images clearly reflect the discrepancy:
versus, the following from MATLAB:
Kindly let me know if I am misunderstanding something, and/or doing something wrong. Also, if any one can point me to a reliable way of computing these functions, I will be very thankful.
Thank you in anticipation.

采纳的回答

Walter Roberson
Walter Roberson 2020-7-11
Do not use inline() anymore. Use matlabFunction() or build an anonymous function or a symbolic expression or a symbolic function.
... And that is the solution in this case. Not just a general principle that inline() is old technology: not using inline() fixed the problem.
There are two versions of hypergeom(). Both live in the symbolic toolbox. One of them is invoked when any of the inputs are symbolic. The other is invoked when all of the arguments are numeric (not symbolic numbers). In the case of all arguments numeric, the code sets the number of digits to 16 and invokes the other version. But 16 digits is not enough for your calculation, and everything overflows.
It is a good question as to why using matlabFunction() does not run into the same problem, since for matlabFunction() all the inputs are numeric. The answer to that is that when you use matlabFunction for this particular expression, The numeric formula for the answer is created and emitted into the function, instead of calling into the symbolic hypergeom.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by