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

Code before:

    _ode_solver_test(_get_examples_ode_sol_euler_undetermined_coeff)


@slow
def test_nth_order_linear_euler_eq_nonhomogeneous_variation_of_parameters():
    x, t = symbols('x, t')
    a, b, c, d = symbols('a, b, c, d', integer=True)
    our_hint = "nth_linear_euler_eq_nonhomogeneous_variation_of_parameters"

    eq = Eq(x**2*diff(f(x),x,2) - 8*x*diff(f(x),x) + 12*f(x), x**2)
    assert our_hint in classify_ode(eq, f(x))

    eq = Eq(a*x**3*diff(f(x),x,3) + b*x**2*diff(f(x),x,2) + c*x*diff(f(x),x) + d*f(x), x*log(x))
    assert our_hint in classify_ode(eq, f(x))

    _ode_solver_test(_get_examples_ode_sol_euler_var_para)


def test_2nd_linear_bessel_symbolic():
    """Test cases for the second order linear Bessel equation solver with symbolic parameters"""
    _ode_solver_test(_get_examples_ode_sol_2nd_linear_bessel_symbolic)



@_add_example_keys
def _get_examples_ode_sol_euler_homogeneous():
    r1, r2, r3, r4, r5 = [rootof(x**5 - 14*x**4 + 71*x**3 - 154*x**2 + 120*x - 1, n) for n in range(5)]
    return {
            'hint': "nth_linear_euler_eq_homogeneous",
            'func': f(x),
            'examples':{
    'euler_hom_01': {
        'eq': Eq(-3*diff(f(x), x)*x + 2*x**2*diff(f(x), x, x), 0),
        'sol': [Eq(f(x), C1 + C2*x**Rational(5, 2))],
    },

    'euler_hom_02': {
        'eq': Eq(3*f(x) - 5*diff(f(x), x)*x + 2*x**2*diff(f(x), x, x), 0),
        'sol': [Eq(f(x), C1*sqrt(x) + C2*x**3)]
    },

    'euler_hom_03': {
        'eq': Eq(4*f(x) + 5*diff(f(x), x)*x + x**2*diff(f(x), x, x), 0),
        'sol': [Eq(f(x), (C1 + C2*log(x))/x**2)]
    },

    'euler_hom_04': {
        'eq': Eq(6*f(x) - 6*diff(f(x), x)*x + 1*x**2*diff(f(x), x, x) + x**3*diff(f(x), x, x, x), 0),
        'sol': [Eq(f(x), C1/x**2 + C2*x + C3*x**3)]
    },

Review comment (suggestion):
Please pay attention to line spacing everywhere. Here there are 3 lines but should be 2. Other places have 1 line but should be 2. Other places have 2 lines but should be 1.

Code after:

    _ode_solver_test(_get_examples_ode_sol_euler_undetermined_coeff)


@slow
def test_nth_order_linear_euler_eq_nonhomogeneous_variation_of_parameters():
    x, t = symbols('x, t')
    a, b, c, d = symbols('a, b, c, d', integer=True)
    our_hint = "nth_linear_euler_eq_nonhomogeneous_variation_of_parameters"

    eq = Eq(x**2*diff(f(x),x,2) - 8*x*diff(f(x),x) + 12*f(x), x**2)
    assert our_hint in classify_ode(eq, f(x))

    eq = Eq(a*x**3*diff(f(x),x,3) + b*x**2*diff(f(x),x,2) + c*x*diff(f(x),x) + d*f(x), x*log(x))
    assert our_hint in classify_ode(eq, f(x))

    _ode_solver_test(_get_examples_ode_sol_euler_var_para)


def test_2nd_linear_bessel_transform():
    """Test cases for the second order linear Bessel equation solver with symbolic parameters"""
    _ode_solver_test(_get_examples_ode_sol_2nd_linear_bessel_transform)


def test_2nd_linear_bessel_transform_rejects_nonhomogeneous():
    """Verify that non-homogeneous equations are rejected."""
    # Non-homogeneous equation: y'' - x^3*y = 10
    # Should NOT be matched. (homogeneous only)
    eq = f(x).diff(x, 2) - x**3*f(x) - 10
    hints = classify_ode(eq, f(x))

    assert '2nd_linear_bessel_transform' not in hints


def test_2nd_linear_bessel_transform_rejects_euler_case():
    """Verify that k=-2 case is rejected."""
    # k=-2 should NOT be matched - it's an Euler equation
    eq = x**(-2)*f(x) + f(x).diff(x, 2)
    hints = classify_ode(eq, f(x))

    assert '2nd_linear_bessel_transform' not in hints


@_add_example_keys
def _get_examples_ode_sol_euler_homogeneous():
    r1, r2, r3, r4, r5 = [rootof(x**5 - 14*x**4 + 71*x**3 - 154*x**2 + 120*x - 1, n) for n in range(5)]
    return {
            'hint': "nth_linear_euler_eq_homogeneous",
            'func': f(x),
            'examples':{
    'euler_hom_01': {