"Matlab besselk(x,y,1)"的确切等价含义是什么?在C ++中? [英] What is the exact equivalent of "Matlab besselk(x,y,1)" in c++?
问题描述
我尝试了boost::math::cyl_bessel_k(x,y) * exp(y)
.在大多数情况下,这等于Matlab缩放的besselk(x,y,1)
.但是在某些情况下(例如x=1
,y=2000
),当besselk(x,y)=0
和boost::math::cyl_bessel_k(x,y)=0
都使用时,Matlab的缩放版本besselk(x,y,1)
为我提供了不同的值,在10^-3
附近有所不同.但是boost::math::cyl_bessel_k(x,y) * exp(y)
返回-nan
.我想找到与Matlab的besselk(x,y,1)
等效的语句.我该如何处理?
I have tried boost::math::cyl_bessel_k(x,y) * exp(y)
. In most cases, this is equal to Matlab's scaled besselk(x,y,1)
. But in some cases (e.g., x=1
, y=2000
) when both besselk(x,y)=0
and boost::math::cyl_bessel_k(x,y)=0
, Matlab's scaled version besselk(x,y,1)
gives me different values varies around 10^-3
. But boost::math::cyl_bessel_k(x,y) * exp(y)
returns -nan
. I'd like to find an equivalent statement for Matlab's besselk(x,y,1)
. How can I handle this?
推荐答案
我在Boost中没有看到满足您需要的任何内容(尽管您可以使用较低级别的函数自己实现它).如您所知,缩放后的贝塞尔函数并非简单地通过乘以exp(z)
来计算. GSL 似乎已合并了此功能,例如,本文和 Amos编写的代码,例如此项目似乎已经做到了,因此可能很有用-那里还有其他项目.
I'm not seeing anything in Boost that does what you need (though you might be able to implement it yourself by using lower-level functions). As you've found out, the scaled Bessel functions are not computed simply by multiplying exp(z)
. The GSL appears to have incorporated this functionality, e.g., gsl_sf_bessel_Knu_scaled
. For an "exact equivalent," you might look at the paper and code by Amos, e.g., CBESK. Both Matlab and Octave appear to use this implementation. However, the code is written in Fortran, so you'd need to translate it or put a wrapper around it (this project appears to have done that so it might be useful – there are others out there too).
您也许还可以使用Matlab的编码器和 codegen
也可以输出一些东西.
You may also be able to use Matlab's Coder and codegen
to output something as well.
这篇关于"Matlab besselk(x,y,1)"的确切等价含义是什么?在C ++中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!