luis
luis

Reputation: 11

Python sympy dsolve error

After reinstalling Python, the following simple code

import sympy as sm

x = sm.Symbol('x')

f = sm.Function('f')

y = sm.dsolve(sm.diff(f (x),x)-3*f(x)(1-0.5f(x)),f(x))

print(y)

gives the following output:

Eq(x + 0.333333333333333*log(1.0*f(x) - 2.0) - 0.333333333333333*log(1.0*f(x)), C1)

but before it used to give me the right answer: f(x) == -2.0/(C1*exp(-3.0*x) - 1.0).

Can someone help me to fix this, please?

Upvotes: 1

Views: 248

Answers (2)

luis
luis

Reputation: 11

First of all I am sorry about the syntax and editing mistakes in the first post. Actually, right now I am running exactly the same code in two computers, one with Anaconda for Windows other with Spyder for Ubuntu, both have Python 2.7, and got two different answers. The code is:

import sympy as sm

x = sm.Symbol('x')
f = sm.Function('f')(x)

y=sm.dsolve(sm.diff(f,x)-3*f*(1-0.5*f),f)
print(y)

In the Ubuntu version I obtain the explicit solution f(x) == -2.0/(C1*exp(-3.0*x) - 1.0) While in the windows machine I obtain the implicit solution Eq(x + 0.3333333333333*log(1.0*f(x) - 2.0) - 0.333333333333*log(1.0*f(x)), C1)

Upvotes: 0

You can try to use Rational instead of float number, as follow:

>>> import sympy as sym
>>> x = sym.Symbol('x')
>>> f = sym.Function('f')(x)
>>> y = sym.dsolve(sym.diff(f,x)-3*f*(1-sym.Rational(1, 2)*f),f)
>>> print y
Eq(f(x), -2/(C1*exp(-3*x) - 1))

Upvotes: 1

Related Questions