0
Under review

Performance of besselh function

Michael_ 7 year бұрын updated by Pavel Holoborodko 7 year бұрын 1

Hello Pavel.


I noticed some performance issues with the besselh-function.

I used mp.Digits(34), mp.GuardDigits(0) and got the following


value=mp(rand(100,100));
tic
value1=besselh(mp('2'),2,mp('1i').*value);
toc
tic
value2=besselj(mp('2'),mp('1i').*value)-mp('1i')*bessely(mp('2'),mp('1i').*value);
toc
tic
value3=besselk(mp('2'),-value)*mp('2')/(mp('1i')*mp('pi'));
toc
Elapsed time is 3.986968 seconds.
Elapsed time is 1.879375 seconds.
Elapsed time is 0.772351 seconds.

which gives of course the same results for value1, value2 and value3. Any possibilty to enhance the performance of besselh to that of besselk?


Best regrads,

Michael


Under review

Dear Michael,


Thank you for your question.


I use different approaches to compute H1 and H2 functions - with the purpose to handle various cases, argument combinations, etc. Overall code is quite convoluted and it clearly can be simplified. This is in my long to-do list for Bessels.


At the moment, as a quick workaround, you can replace besselh in mp.m to rely on J+/-i*Y formulas (value2). Switching to these formulas needs further test of accuracy loss, but they showed good results when I tested them last time - I think it is safe.


But, please note, the K-formula (value3) is valid only for the part of complex plane, as far as I recall.