[PATCH 1/1] Solvers: dsolve - Added Bernoulli case

17 views
Skip to first unread message

Aaron Meurer

unread,
Mar 19, 2009, 12:38:03 AM3/19/09
to sympy-...@googlegroups.com, Aaron Meurer
---
sympy/solvers/solvers.py | 6 ++----
sympy/solvers/tests/test_solvers.py | 1 +
2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/sympy/solvers/solvers.py b/sympy/solvers/solvers.py
index 6a19372..60a1ef5 100644
--- a/sympy/solvers/solvers.py
+++ b/sympy/solvers/solvers.py
@@ -579,17 +579,15 @@ def solve_ODE_first_order(eq, f):
t = C.exp(integrate(r[b]/r[a], x))
tt = integrate(t*(-r[c]/r[a]), x)
return (tt + Symbol("C1"))/t
-
+
#Bernoulli case: a(x)*f'(x)+b(x)*f(x)+c(x)*f(x)^n = 0
n = Wild('n', exclude=[f(x)])
-
+
r = eq.match(a*diff(f(x),x) + b*f(x) + c*f(x)**n)
if r:
t = C.exp((1-r[n])*integrate(r[b]/r[a],x))
tt = (r[n]-1)*integrate(t*r[c]/r[a],x)
return ((tt + Symbol("C1"))/t)**(1/(1-r[n]))
-
-

#other cases of first order odes will be implemented here

diff --git a/sympy/solvers/tests/test_solvers.py b/sympy/solvers/tests/test_solvers.py
index f1e43a0..389b661 100644
--- a/sympy/solvers/tests/test_solvers.py
+++ b/sympy/solvers/tests/test_solvers.py
@@ -142,6 +142,7 @@ def test_ODE_first_order():
x = Symbol('x')
assert dsolve(3*f(x).diff(x) -1, f(x)) == x/3 + Symbol("C1")
assert dsolve(x*f(x).diff(x) -1, f(x)) == log(x) + Symbol("C1")
+ assert dsolve(x*f(x).diff(x)+f(x)-f(x)**2,f(x)) == 1/(x*(Symbol("C1") + 1/x))

def test_ODE_second_order():
f = Function('f')
--
1.6.2

Reply all
Reply to author
Forward
0 new messages