今天在捣鼓MMSE,倒在了贝塞尔函数上,翻找好久,原来C++的cmath里有。
官方文档在这里:
-
第一个链接中是C++,引入cmath,可以调用四种贝塞尔函数。使用以下函数必须支持C++ 17标准,请注意在项目属性中进行设置。
(项目-属性-常规-C++标准,下拉选择C++ 17)
首先给我这条九漏鱼提个醒,
Bessel functions for integer α are also known as cylinder functions or the cylindrical harmonics because they appear in the solution to Laplace’s equation in cylindrical coordinates。
第一类贝塞尔函数:
double cyl_bessel_j(double nu, double x);
float cyl_bessel_jf(float nu, float x);
long double cyl_bessel_jl(long double nu, long double x);
第一类修正的贝塞尔函数,官方文档的 Regular modified cylindrical Bessel functions。我思考了很久它到底是不是 Modified Bessel functions of the first kind…如果不是在stackoverflow里看到一位朋友说:
By regular and irregular, I presume you mean regular or modified Bessel functions.
我可能真的以为这是什么很高深的函数…看来这个说法也不怎么普遍。官方文档里的命名也是让我很不解…我刚刚一拍脑袋,我明明可以看中文版啊,过去切换语言一看——害,是机翻。
double cyl_bessel_i(double nu, double x);
float cyl_bessel_if(float nu, float x);
long double cyl_bessel_il(long double nu, long double x);
第二类贝塞尔函数,AKA Weber functions 、Neumann functions。
double cyl_neumann(double nu, double x);
float cyl_neumannf(float nu, float x);
long double cyl_neumannl(long double nu, long double x);
第二类修正的贝塞尔函数,官方文档里的 Irregular modified cylindrical Bessel functions。
double cyl_bessel_k(double nu, double x);
float cyl_bessel_kf(float nu, float x);
long double cyl_bessel_kl(long double nu, long double x);
第二个链接中是math.h中关于贝塞尔函数的说明。
如果在C中,引入math.h以后的函数调用与C++不同。math.h里的贝塞尔函数只能调用整数阶的,感觉没有C++那么自由。
double _j0(double x);
double _j1(double x);
double _jn(int n, double x);
double _y0(double x);
double _y1(double x);
double _yn(int n, double x);
以下是官方示例。
// crt_bessel1.c
#include <math.h>
#include <stdio.h>
int main( void )
{
double x = 2.387;
int n = 3, c;
printf( "Bessel functions for x = %f:\n", x );
printf( " Kind Order Function Result\n\n" );
printf( " First 0 _j0( x ) %f\n", _j0( x ) );
printf( " First 1 _j1( x ) %f\n", _j1( x ) );
for( c = 2; c < 5; c++ )
printf( " First %d _jn( %d, x ) %f\n", c, c, _jn( c, x ) );
printf( " Second 0 _y0( x ) %f\n", _y0( x ) );
printf( " Second 1 _y1( x ) %f\n", _y1( x ) );
for( c = 2; c < 5; c++ )
printf( " Second %d _yn( %d, x ) %f\n", c, c, _yn( c, x ) );
}
总结,还是要多学习唉。
[1] https://encyclopedia.thefreedictionary.com/Bessel+function