My first patch

6 views
Skip to first unread message

asmeurer

unread,
Mar 19, 2009, 12:43:30 AM3/19/09
to sympy-patches
Hi. I am planning on applying to work with sympy for the Google Summer
of Code 2009 (see here:
http://groups.google.com/group/sympy/browse_thread/thread/bfccfe3e4ce60c34/bb3093a30ea1d168#bb3093a30ea1d168)

Anyway, Ondrej has requested that I post my patch here, so here it is:

---
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

Ondrej Certik

unread,
Mar 19, 2009, 12:54:47 AM3/19/09
to sympy-...@googlegroups.com

Thanks for the patch. Maybe you forgot to attach the actual patch
implementing this equation?


This doesn't work if I run it:

In [1]: dsolve(x*f(x).diff(x)+f(x)-f(x)**2,f(x))
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)

/home/ondrej/repos/sympy/<ipython console> in <module>()

/home/ondrej/repos/sympy/sympy/solvers/solvers.pyc in dsolve(eq, funcs)
536 return solve_ODE_second_order(eq, f(x))
537 elif order == 1:
--> 538 return solve_ODE_first_order(eq, f(x))
539 else:
540 raise NotImplementedError("Not a differential equation!")

/home/ondrej/repos/sympy/sympy/solvers/solvers.pyc in
solve_ODE_first_order(eq, f)
583 #other cases of first order odes will be implemented here

584
--> 585 raise NotImplementedError("solve_ODE_first_order: Cannot
solve " + str(eq))
586
587 def solve_ODE_second_order(eq, f):

NotImplementedError: solve_ODE_first_order: Cannot solve x*D(f(x), x)
+ f(x) - f(x)**2

Ondrej

asmeurer

unread,
Mar 19, 2009, 1:09:47 AM3/19/09
to sympy-patches
> Thanks for the patch. Maybe you forgot to attach the actual patch
> implementing this equation?

I'm not sure what you mean here. I followed each step on the git quick
guide you linked to. Is there something not listed there that I
needed to do?

Aaron

Ondrej Certik

unread,
Mar 19, 2009, 1:15:39 AM3/19/09
to sympy-...@googlegroups.com

Yes, since you created 2 patches, you need to post both patches.

If I apply your patch above, it doesn't work, so you need to fix it.

Ondrej

asmeurer

unread,
Mar 19, 2009, 10:59:01 AM3/19/09
to sympy-patches
> Yes, since you created 2 patches, you need to post both patches.
Here is the earlier patch. It is just the same as the other one but
without the tests:

---
sympy/solvers/solvers.py | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/sympy/solvers/solvers.py b/sympy/solvers/solvers.py
index 6377ac8..6a19372 100644
--- a/sympy/solvers/solvers.py
+++ b/sympy/solvers/solvers.py
@@ -563,7 +563,7 @@ def solve_ODE_first_order(eq, f):
"""
solves many kinds of first order odes, different methods are used
depending on the form of the given equation. Now the linear
- case is implemented.
+ and Bernoulli cases are implemented.
"""
from sympy.integrals.integrals import integrate
x = f.args[0]
@@ -579,6 +579,17 @@ 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

--
1.6.2

> If I apply your patch above, it doesn't work, so you need to fix it.

Ok, I see what happened. I thought that git would apply the whole
patch based on the diff of what it had originally downloaded, but it
only put plus signs on the lines that I had changed since the first
patch. I guess I need to learn more about how git works. Once
again, sorry about that.

Ondrej Certik

unread,
Mar 19, 2009, 11:40:49 AM3/19/09
to sympy-...@googlegroups.com

Thanks, I'll give it a try in the evening.

>
>> If I apply your patch above, it doesn't work, so you need to fix it.
>
> Ok, I see what happened.  I thought that git would apply the whole
> patch based on the diff of what it had originally downloaded, but it
> only put plus signs on the lines that I had changed since the first
> patch.  I guess I need to learn more about how git works.   Once
> again, sorry about that.

If you committed two patches (do "git log" to see), just do

git format-patch -2

Ondrej

Reply all
Reply to author
Forward
0 new messages