Repository: sympy/sympy

Issue:
Bug in dsolve(_, f(x), hint='2nd_power_series_regular')
```python
>>> a = Symbol('a')
>>> f = Function('f')
>>> x = Symbol('x')
>>> -a*x*f(x) + x*f(x).diff(x, 2) + f(x).diff(x)
                2                 
               d          d       
-a⋅x⋅f(x) + x⋅───(f(x)) + ──(f(x))
                2         dx      
              dx                  
>>> dsolve(_, f(x), hint='2nd_power_series_regular')
Traceback (most recent call last):
  File "/usr/lib/python3.6/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
  File "/home/czgdp1807ssd/sympy_project/sympy/sympy/solvers/ode/ode.py", line 656, in dsolve
    return _helper_simplify(eq, hint, hints, simplify, ics=ics)
  File "/home/czgdp1807ssd/sympy_project/sympy/sympy/solvers/ode/ode.py", line 687, in _helper_simplify
    sols = solvefunc(eq, func, order, match)
  File "/home/czgdp1807ssd/sympy_project/sympy/sympy/solvers/ode/ode.py", line 3696, in ode_2nd_power_series_regular
    term = series(term, n=1, x0=x0)
  File "/home/czgdp1807ssd/sympy_project/sympy/sympy/series/series.py", line 65, in series
    return expr.series(x, x0, n, dir)
  File "/home/czgdp1807ssd/sympy_project/sympy/sympy/core/expr.py", line 2891, in series
    raise ValueError('x must be given for multivariate functions.')
ValueError: x must be given for multivariate functions.
```

Discussion:

Patch:
diff --git a/sympy/solvers/ode/ode.py b/sympy/solvers/ode/ode.py
index d5f275bccc..8d78724f6a 100644
--- a/sympy/solvers/ode/ode.py
+++ b/sympy/solvers/ode/ode.py
@@ -3602,7 +3602,7 @@ def ode_2nd_power_series_regular(eq, func, order, match):
         if not term.has(x):
             indicial.append(term)
         else:
-            term = series(term, n=1, x0=x0)
+            term = series(term, x=x, n=1, x0=x0)
             if isinstance(term, Order):
                 indicial.append(S.Zero)
             else:


Test patch:
diff --git a/sympy/solvers/ode/tests/test_ode.py b/sympy/solvers/ode/tests/test_ode.py
index ed8d54ccba..dcc1ceecd1 100644
--- a/sympy/solvers/ode/tests/test_ode.py
+++ b/sympy/solvers/ode/tests/test_ode.py
@@ -902,7 +902,7 @@ def test_2nd_power_series_ordinary():
 
 
 def test_2nd_power_series_regular():
-    C1, C2 = symbols("C1 C2")
+    C1, C2, a = symbols("C1 C2 a")
     eq = x**2*(f(x).diff(x, 2)) - 3*x*(f(x).diff(x)) + (4*x + 4)*f(x)
     sol = Eq(f(x), C1*x**2*(-16*x**3/9 + 4*x**2 - 4*x + 1) + O(x**6))
     assert dsolve(eq, hint='2nd_power_series_regular') == sol
@@ -927,6 +927,18 @@ def test_2nd_power_series_regular():
     assert dsolve(eq, hint='2nd_power_series_regular') == sol
     assert checkodesol(eq, sol) == (True, 0)
 
+    eq = x*f(x).diff(x, 2) + f(x).diff(x) - a*x*f(x)
+    sol = Eq(f(x), C1*(a**2*x**4/64 + a*x**2/4 + 1) + O(x**6))
+    assert dsolve(eq, f(x), hint="2nd_power_series_regular") == sol
+    assert checkodesol(eq, sol) == (True, 0)
+
+    eq = f(x).diff(x, 2) + ((1 - x)/x)*f(x).diff(x) + (a/x)*f(x)
+    sol = Eq(f(x), C1*(-a*x**5*(a - 4)*(a - 3)*(a - 2)*(a - 1)/14400 + \
+        a*x**4*(a - 3)*(a - 2)*(a - 1)/576 - a*x**3*(a - 2)*(a - 1)/36 + \
+        a*x**2*(a - 1)/4 - a*x + 1) + O(x**6))
+    assert dsolve(eq, f(x), hint="2nd_power_series_regular") == sol
+    assert checkodesol(eq, sol) == (True, 0)
+
 
 def test_issue_15056():
     t = Symbol('t')