hypergeom without symbolic math toolbox

Hi, is there any way to use the hypergeom function without having the symbolic math toolbox? I have tried some of the posted in the file exchange, but they all tend to give different results for large arguments compared to hypergeom. Thanks

10 件のコメント

Dyuman Joshi
Dyuman Joshi 2023 年 8 月 21 日
"I have tried some of the posted in the file exchange, but they all tend to give different results for large arguments compared to hypergeom."
The functions posted in FEX are numerical where as the hypergeom function is symbolical. There will be a difference in the precision of the values obtained.
"is there any way to use the hypergeom function without having the symbolic math toolbox?"
No, atleast not symbolically.
Why do you not want to use the symbolic math toolbox? Or do you not have access to it?
Star Strider
Star Strider 2023 年 8 月 21 日
Please describe the problem you want to solve.
Eze Far
Eze Far 2023 年 8 月 21 日
I don't have the symbolic math toolbox.
I'm fitting a function to some data. The function involves the confluent hypergeometric function of the first kind 1F1(a,b,z), where in my case z is real and can go to large values. I'm thinking to use the integral expression, but I guess it will take much longer than hypergeom. Thank you
Torsten
Torsten 2023 年 8 月 21 日
編集済み: Torsten 2023 年 8 月 21 日
I'm thinking to use the integral expression, but I guess it will take much longer than hypergeom.
Just test it:
F = @(a,b,z) gamma(b)/(gamma(b-a)*gamma(a))*integral(@(t) exp(z.*t).*t.^(a-1).*(1-t).^(b-a-1),0,1);
tic
for i = 1:1000
F(1,2,-pi);
end
toc
Elapsed time is 0.119686 seconds.
tic
for i = 1:1000
hypergeom(1,2,-pi);
end
toc
Elapsed time is 8.940058 seconds.
Dyuman Joshi
Dyuman Joshi 2023 年 8 月 21 日
@Torsten, that function won't work when a==b, and it does not provide a solution for large(ish) values.
(One could argue if 100 is large or not)
F = @(a,b,z) gamma(b)/(gamma(b-a)*gamma(a))*integral(@(t) exp(z.*t).*t.^(a-1).*(1-t).^(b-a-1),0,1);
%1
F(1,2,3)
ans = 6.3618
hypergeom(1,2,3)
ans = 6.3618
%2
F(1e2,1e1,1e0)
Warning: Inf or NaN value encountered.
ans = NaN
hypergeom(1e2,1e1,1e0)
ans = 2.4862e+03
%3
F(10,5,1)
Warning: Minimum step size reached near x = 1. There may be a singularity, or the tolerances may be too tight for this problem.
ans = 0
hypergeom(10,5,1)
ans = 6.4804
Torsten
Torsten 2023 年 8 月 21 日
Yes, it was a lousy attempt ... But at least it shows that numerical evaluation can be much faster - if it works :-)
Eze Far
Eze Far 2023 年 8 月 21 日
It works just fine for a=1/2 and b=3/2. Thanks
Walter Roberson
Walter Roberson 2023 年 8 月 21 日
hypergeomic function has a tendancy towards large intermediate values.
Dyuman Joshi
Dyuman Joshi 2023 年 8 月 21 日
"It works just fine for a=1/2 and b=3/2."
The FEX submissions didn't work for these values?
the cyclist
the cyclist 2023 年 8 月 21 日
For some values of parameters, hypergeometric variates can also be well approximated by either binomial or poisson variates. (Web search turns these up, if that sounds useful.)

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSymbolic Math Toolbox についてさらに検索

質問済み:

2023 年 8 月 21 日

コメント済み:

2023 年 8 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by