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