Hypergeometric functions(1F2) in matlab

I want to use the hypergeometric function [def] this exists in mathematica (wolfram). I tried this
function result = hypegeo(q, r)
qr = q * r;
z = - (qr)^2 / 4;
inp=[3/2,[1, 5/2],z];
F2_value = hypergeom(1,2,inp);
result = (1/3) * F2_value;
end
but for me looking at the definition of the hyper geometric function in matlab doesnt seem exaclty the same as the one in wolfram.
if they arent the same, is there a way to use mathmatica functions in matlab or some other workaround for this?

 채택된 답변

Walter Roberson
Walter Roberson 2024년 6월 11일

1 개 추천

In MATLAB, some of the parameters are implicit according to the length of the other parameters.
function result = hypegeo(q, r)
qr = q * r;
z = - (qr)^2 / 4;
F2_value = hypergeom(3/2, [1, 5/2], z);
result = (1/3) * F2_value;
end

댓글 수: 3

Reminder:
inp=[3/2,[1, 5/2],z];
means the same as
inp = horzcat(3/2, [1, 5/2], z)
which is the same as
inp = horzcat(3/2, horzcat(1, 5/2), z);
which simplifies to
inp = horzcat(3/2, 1, 5/2, z)
Using [] is a shortcut to list concatenation, and everything will get "flattened". [] inside of [] does not result in the inner [] elements being grouped together somehow.
The syntax for creating groups would be
inp = {3/2,[1, 5/2],z};
However, hypergeom() does not accept cell arrays.
Thanks for the explanation, a small question in case I wanted to use a python function for general knowledge,
as an example, is this a correct way to do it?
function result = hypegeo(q, r)
py=pyenv(Version='directory');
py
% Define parameters
a = 3/2;
b = 1;
c = 5/2;
z = -1*((q*r)^2)/4;
% Call mpmath's hyp1f2 function
result_py = py.pyrun(mpmath.hyper(a, b, c, z));
% Convert Python result to MATLAB double
result = double(result_py);
end
No, mpmath.hyper accepts a, b, z parameters, where a and b are tuples. There is no hyper(a, b, c, z)
You should be using
a = 3/2;
b1 = 1;
b2 = 5/2;
z = -1*((q*r)^2)/4;
result_py = py.pyrun(mpmath.hyp1f2(a, b1, b2, z));
or something similar.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Shivani
Shivani 2024년 6월 11일

0 개 추천

Hello @ALI,
You can refer to the following file exchange link for implementation details of calculating a generalized Hypergeometric function: https://www.mathworks.com/matlabcentral/fileexchange/5616-generalized-hypergeometric-function
Additionally, the following MATLAB Answer threads also provide details on implementing a Hypergeometric function in MATLAB.
Hope this helps!

댓글 수: 1

function result = hypegeo(q, r)
py=pyenv(Version='directory');
py
% Define parameters
a = 3/2;
b = 1;
c = 5/2;
z = -1*((q*r)^2)/4;
% Call mpmath's hyp1f2 function
result_py = py.pyrun(mpmath.hyper(a, b, c, z));
% Convert Python result to MATLAB double
result = double(result_py);
end
I tried this I think its correct but it gives an errorr with loading python functions

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품

릴리스

R2023b

질문:

ALI
2024년 6월 11일

댓글:

2024년 6월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by