1

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?

Kalpesh Dusane
  • 1,477
  • 3
  • 20
  • 27
luis
  • 11
  • 2
  • Please format your code properly by [edit]ing it. Also remove those line numbers. And what do you mean "it used to give" you the right answer? Please read [ask]. – Andras Deak -- Слава Україні Oct 10 '16 at 19:39
  • What version of sympy were you using previously? What version are you using here? I also notice that there are some syntax errors in the code that's posted. Would it be possible to post code that actually gives the output you displayed? – Bill Bell Oct 10 '16 at 19:49

2 Answers2

1

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))
asmeurer
  • 86,894
  • 26
  • 169
  • 240
0

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)

Svaberg
  • 1,501
  • 1
  • 19
  • 40
luis
  • 11
  • 2