1 #ifndef STAN_MATH_PRIM_FUN_BESSEL_FIRST_KIND_HPP
2 #define STAN_MATH_PRIM_FUN_BESSEL_FIRST_KIND_HPP
3
4 #include <stan/math/prim/meta.hpp>
5 #include <stan/math/prim/err.hpp>
6 #include <boost/math/special_functions/bessel.hpp>
7 #include <stan/math/prim/functor/apply_scalar_binary.hpp>
8
9 namespace stan {
10 namespace math {
11
12 /**
13 *
14 \f[
15 \mbox{bessel\_first\_kind}(v, x) =
16 \begin{cases}
17 J_v(x) & \mbox{if } -\infty\leq x \leq \infty \\[6pt]
18 \textrm{error} & \mbox{if } x = \textrm{NaN}
19 \end{cases}
20 \f]
21
22 \f[
23 \frac{\partial\, \mbox{bessel\_first\_kind}(v, x)}{\partial x} =
24 \begin{cases}
25 \frac{\partial\, J_v(x)}{\partial x} & \mbox{if } -\infty\leq x\leq \infty
26 \\[6pt] \textrm{error} & \mbox{if } x = \textrm{NaN} \end{cases} \f]
27
28 \f[
29 J_v(x)=\left(\frac{1}{2}x\right)^v
30 \sum_{k=0}^\infty \frac{\left(-\frac{1}{4}x^2\right)^k}{k!\, \Gamma(v+k+1)}
31 \f]
32
33 \f[
34 \frac{\partial \, J_v(x)}{\partial x} = \frac{v}{x}J_v(x)-J_{v+1}(x)
35 \f]
36 *
37 */
38 template <typename T2, require_arithmetic_t<T2>* = nullptr>
bessel_first_kind(int v,const T2 z)39 inline T2 bessel_first_kind(int v, const T2 z) {
40 check_not_nan("bessel_first_kind", "z", z);
41 return boost::math::cyl_bessel_j(v, z);
42 }
43
44 /**
45 * Enables the vectorised application of the bessel first kind function, when
46 * the first and/or second arguments are containers.
47 *
48 * @tparam T1 type of first input
49 * @tparam T2 type of second input
50 * @param a First input
51 * @param b Second input
52 * @return Bessel first kind function applied to the two inputs.
53 */
54 template <typename T1, typename T2, require_any_container_t<T1, T2>* = nullptr,
55 require_not_var_matrix_t<T2>* = nullptr>
bessel_first_kind(const T1 & a,const T2 & b)56 inline auto bessel_first_kind(const T1& a, const T2& b) {
57 return apply_scalar_binary(a, b, [&](const auto& c, const auto& d) {
58 return bessel_first_kind(c, d);
59 });
60 }
61
62 } // namespace math
63 } // namespace stan
64 #endif
65