在数学中,微分方程
尤为重要。方程的解是参数的函数 。对于的积分值和半积分值 ,特别有趣的解,被称为圆柱贝塞尔函数,以德国著名数学家弗里德里希·威廉·贝塞尔(Friedrich Wilhelm Bessel)的名字命名。之所以要求在下面给出的解释中,将是整数还是半整数将是清楚的。
由于这是一个二阶微分方程,因此必须有两个线性独立的解,分别称为第一类和第二类。因此,可以使用Frobenius方法手动求解微分方程。第一种贝塞尔函数,用于复杂参数称为第一类修改贝塞尔函数,并用表示 。该方法的应用将产生一个无限级数,其中包含和 ,由
由于表达式包含Gamma 函数 ,该函数只能针对整数和半整数值进行计算,因此参数必须是整数或半整数。
C++ 17(GCC 7.1)标准库cmath
提供了一些函数来计算第一类圆柱贝塞尔函数的值(std::cyl_bessel_j)
(此处未讨论,但与我们所讨论的非常相似)和值常规贝塞尔函数(std::cyl_bessel_i)
。两者在小输入时都具有明显的精度,可用于各种工程应用中。
例子:
Input: x = 2.798465, v = 0
Output: 4.152234090041574
Input: x = 3.04513, v = 0.5
Output: 4.792979684692604
注意:以下源代码只能在C++ 17和更高版本上运行。可以在此处检查给定代码的运行示例。要运行其他输入,请访问链接,然后单击右下角的“编辑”。
// C++17 code for bessel function
#include
using namespace std;
// Compute the answer from the formulae for first 10 terms
long double answer(long double x, long double v)
{
long double ans_by_expansion = 0;
long double fact = 1;
for (int k = 0; k < 10; fact = fact * (++k)) {
ans_by_expansion += pow((x / 2), (2 * k)) / pow(fact, 2);
cout << "ans_by_expansion till term k = ";
cout << k << " is " << ans_by_expansion << "\n";
}
return ans_by_expansion;
}
// Driver code
int main()
{
long double x = 2.798465;
long double v = 0;
// Compute the Regular Modified Bessel Function
// for v = 0, x = 2.798465
long double ans_by_function = cyl_bessel_i(v, x);
cout << setprecision(15) << fixed;
cout << "The answer by function for "
<< "Regular_Modified_Bessel_Function" << endl
<< "(" << v << ", " << x << ") = "
<< ans_by_function << "\n";
// calculate answer by expansion
long double ans_by_expansion = answer(x, v);
cout << "Absolute Error in answer by both the methods is = ";
cout << abs(ans_by_expansion - ans_by_function) << "\n";
return 0;
}
输出:
The answer by function for Regular_Modified_Bessel_Function
(0.000000000000000, 2.798465000000000) = 4.152234090041574
ans_by_expansion till term k = 0 is 1.000000000000000
ans_by_expansion till term k = 1 is 2.957851589056250
ans_by_expansion till term k = 2 is 3.916147300248771
ans_by_expansion till term k = 3 is 4.124614053687001
ans_by_expansion till term k = 4 is 4.150123238967278
ans_by_expansion till term k = 5 is 4.152120966924739
ans_by_expansion till term k = 6 is 4.152229612892962
ans_by_expansion till term k = 7 is 4.152233953968095
ans_by_expansion till term k = 8 is 4.152234086767796
ans_by_expansion till term k = 9 is 4.152234089977698
Absolute Error in answer by both the methods is = 0.000000000063876