Cleaned up dsolve, added PDE support for deriv_degree, moved ODE handling
into its own function and add solver stub for PDEs.

Signed-off-by: Priit Laes <pl...@plaes.org>
---
diff --git a/sympy/solvers/solvers.py b/sympy/solvers/solvers.py
index 60a1ef5..30722c0 100644
--- a/sympy/solvers/solvers.py
+++ b/sympy/solvers/solvers.py
@@ -522,27 +522,29 @@ def dsolve(eq, funcs):
         else:
             f = funcs
 
-        x = f.args[0]
-        f = f.func
-
-        #We first get the order of the equation, so that we can choose the
-        #corresponding methods. Currently, only first and second
-        #order odes can be handled.
-        order = deriv_degree(eq, f(x))
-
-        if  order > 2 :
-           raise NotImplementedError("dsolve: Cannot solve " + str(eq))
-        elif order == 2:
-            return solve_ODE_second_order(eq, f(x))
-        elif order == 1:
-            return solve_ODE_first_order(eq, f(x))
+        # Determine the order of the equation
+        order = deriv_degree(eq, f.func)
+
+        if len(f.args) == 1:
+            return dsolve_ODE(eq, f, order)
         else:
-            raise NotImplementedError("Not a differential equation!")
+            return dsolve_PDE(eq, f, order)
+
+    raise NotImplementedError("Cannot handle this differential equation!")
+
+def dsolve_PDE(eq, f, order):
+    raise NotImplementedError("dsolve_PDE: Cannot solve " + str(eq))
+
+def dsolve_ODE(eq, f, order):
+    if order == 1:
+        return solve_ODE_first_order(eq, f)
+    elif order == 2:
+        return solve_ODE_second_order(eq, f)
+    raise NotImplementedError("dsolve_ODE: Cannot solve " + str(eq))
 
 def deriv_degree(expr, func):
     """ get the order of a given ode, the function is implemented
     recursively """
-    a = Wild('a', exclude=[func])
 
     order = 0
     if isinstance(expr, Derivative):
@@ -551,12 +553,9 @@ def deriv_degree(expr, func):
         for arg in expr.args:
             if isinstance(arg, Derivative):
                 order = max(order, len(arg.symbols))
-            elif expr.match(a):
-                order = 0
             else :
                 for arg1 in arg.args:
                     order = max(order, deriv_degree(arg1, func))
-
     return order
 
 def solve_ODE_first_order(eq, f):
diff --git a/sympy/solvers/tests/test_solvers.py 
b/sympy/solvers/tests/test_solvers.py
index 389b661..d22b75d 100644
--- a/sympy/solvers/tests/test_solvers.py
+++ b/sympy/solvers/tests/test_solvers.py
@@ -165,12 +165,15 @@ def test_ODE_1():
 
 def test_deriv_degree():
     f = Function('f')
-    x = Symbol('x')
+    x,y = symbols('xy')
+    # ODEs
     assert deriv_degree(3*x*exp(f(x)), f(x)) == 0
     assert deriv_degree(x*diff(f(x),x)+3*x*f(x)-sin(x)/x, f(x)) == 1
     assert deriv_degree(x**2*f(x).diff(x,x)+x*diff(f(x),x)-f(x),f(x)) == 2
     assert deriv_degree(diff(x*exp(f(x)),x,x), f(x)) == 2
     assert deriv_degree(diff(x*diff(x*exp(f(x)), x,x), x), f(x)) == 3
+    # PDEs
+    assert deriv_degree(x**2*f(x,y).diff(x,x)-y**2*f(x,y).diff(y,y),f(x,y)) == 
2
 
 # Note: multiple solutions exist for some of these equations, so the tests
 # should be expected to break if the implementation of the solver changes
--
cgit v0.8.2


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

Reply via email to