Updates:
        Cc: smichr

Comment #1 on issue 1765 by asmeurer: classify_ode((x**2 +  
f(x)**2)*f(x).diff(x) - 2*x*f(x), f(x)) is wrong
http://code.google.com/p/sympy/issues/detail?id=1765

The 1st_linear part used to work.  It was broken with this commit:

commit d0906fff0dc21ed69369f3cfb77af358f119ec68
Author: Chris Smith <smi...@gmail.com>
Date:   Mon Nov 9 06:02:59 2009 +0545

     1686: linear ODE identification

         A more robust method is used to identify a
         linear ODE.  collect() cannot collect on more
         than one term, and match doesn't pull together
         multiple terms so the added test (a previously
         failing expression) is identified by pulling
         out the coefficients of the terms of interest
         and checking to see that what was collected
         reconstructs the original equation.

diff --git a/sympy/solvers/ode.py b/sympy/solvers/ode.py
index 1662aa8..ef71dcb 100755
--- a/sympy/solvers/ode.py
+++ b/sympy/solvers/ode.py
@@ -584,8 +584,16 @@ def classify_ode(eq, func, dict=False):
          # We can save a lot of time by skipping these if the ODE isn't 1st  
order

          # Linear case: a(x)*y'+b(x)*y+c(x) == 0
-        r = reduced_eq.match(a*df + b*f(x) + c)
-        if r:
+        if eq.is_Add:
+            ind, dep = reduced_eq.as_independent(f)
+        else:
+            u = Symbol('u', dummy=True)
+            ind, dep = (reduced_eq + u).as_independent(f)
+            ind, dep = [tmp.subs(u, 0) for tmp in [ind, dep]]
+        r = {a: dep.coeff(df, expand=False) or 0,
+             b: dep.coeff(f(x), expand=False) or 0,
+             c: ind}
+        if (r[a]*df + r[b]*f(x) + r[c]).expand() - reduced_eq == 0:
              r['a'] = a
              r['b'] = b
              r['c'] = c
diff --git a/sympy/solvers/tests/test_ode.py  
b/sympy/solvers/tests/test_ode.py
index 1a05945..57ff0bb 100644
--- a/sympy/solvers/tests/test_ode.py
+++ b/sympy/solvers/tests/test_ode.py
@@ -1055,3 +1055,6 @@ def test_unexpanded_Liouville_ODE():
      assert dsolve(eq2, f(x)) in (sol2, sol2s)
      assert checkodesol(eq2, f(x), sol2, order=2, solve_for_func=False)[0]

+def test_1686():
+    eq = x + C1*(x + diff(f(x), x) + f(x)) + diff(f(x), x) + f(x) + 2
+    assert classify_ode(eq, f(x)) == ('1st_linear', '1st_linear_Integral')


--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

--

You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to sympy-iss...@googlegroups.com.
To unsubscribe from this group, send email to 
sympy-issues+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy-issues?hl=en.


Reply via email to