Repository: sympy/sympy
File: sympy/solvers/ode/single.py (Python)

Code before:
            else:
                coeff2[d4] = factor(_coeff2[b]).match(d4**2)[d4]

            self.rn = {'n':coeff2[d4], 'a4':coeff2[c4], 'd4':coeff2[a4]}
            self.rn['c4'] = coeff1[a4]
            self.rn['b4'] = point
            return True
        return False

    def _get_general_solution(self, *, simplify_flag: bool = True):
        f = self.ode_problem.func.func
        x = self.ode_problem.sym
        n = self.rn['n']
        a4 = self.rn['a4']
        c4 = self.rn['c4']
        d4 = self.rn['d4']
        b4 = self.rn['b4']
        n = sqrt(n**2 + Rational(1, 4)*(c4 - 1)**2)
        (C1, C2) = self.ode_problem.get_numbered_constants(num=2)
        return [Eq(f(x), ((x**(Rational(1-c4,2)))*(C1*besselj(n/d4,a4*x**d4/d4)
            + C2*bessely(n/d4,a4*x**d4/d4))).subs(x, x-b4))]


class SecondLinearBesselSymbolic(SingleODESolver):
    r"""
    Solves second-order ODEs of the form y'' + A*x^k*y = 0 where k is symbolic.

    These equations have solutions in terms of Bessel functions.

    The general solution is:

    .. math:: y(x) = \sqrt{x} \left[C_1 J_\nu(z) + C_2 Y_\nu(z)\right]

    where :math:`\nu = \frac{1}{k+2}` and :math:`z = \frac{2}{k+2} x^{(k+2)/2}`

    Examples
    ========

    >>> from sympy import symbols, Function, dsolve, Derivative
    >>> x, k = symbols('x k')
    >>> y = Function('y')
    >>> dsolve(Derivative(y(x), (x, 2)) + x**k*y(x))
    Eq(y(x), sqrt(x)*(C1*besselj(1/(k + 2), 2*x**(k/2 + 1)/(k + 2)) +
                  C2*bessely(1/(k + 2), 2*x**(k/2 + 1)/(k + 2))))

    References
    ==========
    - Abramowitz & Stegun, Handbook of Mathematical Functions, 9.1.52
    - https://eqworld.ipmnet.ru/en/solutions/ode/ode0201.pdf
    """
    hint = "2nd_linear_bessel_symbolic"

Review comment (security):
This class should be added to `doc/src/modules/solvers/ode.rst`. Please check how it looks in the docs build because I think maybe the unescaped ascii-mathematics here might be problematic:
https://docs.sympy.org/latest/contributing/documentation-style-guide.html

Code after:
            else:
                coeff2[d4] = factor(_coeff2[b]).match(d4**2)[d4]

            self.rn = {'n':coeff2[d4], 'a4':coeff2[c4], 'd4':coeff2[a4]}
            self.rn['c4'] = coeff1[a4]
            self.rn['b4'] = point
            return True
        return False

    def _get_general_solution(self, *, simplify_flag: bool = True):
        f = self.ode_problem.func.func
        x = self.ode_problem.sym
        n = self.rn['n']
        a4 = self.rn['a4']
        c4 = self.rn['c4']
        d4 = self.rn['d4']
        b4 = self.rn['b4']
        n = sqrt(n**2 + Rational(1, 4)*(c4 - 1)**2)
        (C1, C2) = self.ode_problem.get_numbered_constants(num=2)
        return [Eq(f(x), ((x**(Rational(1-c4,2)))*(C1*besselj(n/d4,a4*x**d4/d4)
            + C2*bessely(n/d4,a4*x**d4/d4))).subs(x, x-b4))]


class SecondLinearBesselTransform(SingleODESolver):
    r"""
    Solves second-order ODEs of the form y'' + A*x^k*y = 0.

    These equations have solutions in terms of Bessel functions.

    The general solution is:

    .. math:: y(x) = \sqrt{x} \left[C_1 J_\nu(z) + C_2 Y_\nu(z)\right]

    where :math:`\nu = \frac{1}{k+2}` and :math:`z = \frac{2}{k+2} x^{(k+2)/2}`

    Examples
    ========

    >>> from sympy import symbols, Function, dsolve, Derivative
    >>> x, k = symbols('x k')
    >>> y = Function('y')
    >>> dsolve(Derivative(y(x), (x, 2)) + x**k*y(x))
    Eq(y(x), sqrt(x)*(C1*besselj(1/(k + 2), 2*x**(k/2 + 1)/(k + 2)) +
                  C2*bessely(1/(k + 2), 2*x**(k/2 + 1)/(k + 2))))

    References
    ==========
    - Abramowitz & Stegun, Handbook of Mathematical Functions, 9.1.52
    - https://eqworld.ipmnet.ru/en/solutions/ode/ode0201.pdf
    """
    hint = "2nd_linear_bessel_transform"