Hi,

I'm not sure if I'm missing a trick but I've been trying to use dsolve and
it seems it doesn't work in many simple cases. I've put some examples
below, tested with sympy 1.2 installed using pip. I don't know if any of
the below is me using dsolve incorrectly or should be considered a bug or
is just a reflection of it being a work in progress.

I want to solve the heat/diffusion equation for heat in a cylinder with an
exponential heat term:

$ isympy

In [*1*]: eqn = Derivative(Derivative(f(x),x)*x,x)/x - exp(x)


In [*2*]: eqn

Out[*2*]:

       d ⎛  d       ⎞

       ──⎜x⋅──(f(x))⎟

   x   dx⎝  dx      ⎠

- ℯ  + ──────────────

             x


In [*3*]: dsolve(eqn, f(x))

---------------------------------------------------------------------------

NotImplementedError

It strikes me as odd that sympy can't solve this since it's essentially an
algebraic rearrangement to get f here and all that is needed is to
understand that d/dx can be integrated. Sympy can do the integrals:

In [*16*]: res = expand((simplify(eqn * x).integrate(x) +
C1)/x).integrate(x) + C2

    ...:


In [*17*]: res

Out[*17*]:

                         x

C₁⋅log(x) + C₂ + f(x) - ℯ  + Ei(x)


In [*18*]: solve(res, f(x))

Out[*18*]:

⎡                   x        ⎤

⎣-C₁⋅log(x) - C₂ + ℯ  - Ei(x)⎦

The algorithm for this is essentially the same as solving an algebraic
equation. If I replace the derivatives with logs then solve can do it:

In [*23*]: eqn = log(log(f(x))*x)/x - exp(x)


In [*24*]: eqn

Out[*24*]:

   x   log(x⋅log(f(x)))

- ℯ  + ────────────────

              x


In [*25*]: solve(eqn, f(x))

Out[*25*]:

⎡     x⎤

⎢  x⋅ℯ ⎥

⎢ ℯ    ⎥

⎢ ─────⎥

⎢   x  ⎥

⎣ℯ     ⎦

If I use f(x).diff(x) rather than Derivative then it looks more complicated
but should work:

In [*26*]: eqn = ((f(x)).diff(x)*x).diff(x)/x - exp(x)


In [*27*]: eqn

Out[*27*]:

           2

          d          d

       x⋅───(f(x)) + ──(f(x))

           2         dx

   x     dx

- ℯ  + ──────────────────────

                 x


In [*28*]: dsolve(eqn)

---------------------------------------------------------------------------

NotImplementedError

The automatic expansion of the product rule here leaves us in a slightly
trickier position but again there is a general rule that sympy is
overlooking here: Use a substitution f' = g to bring it to 1st order:

In [*32*]: eqn = (g(x)*x).diff(x)/x - exp(x)


In [*33*]: eqn

Out[*33*]:

         d

       x⋅──(g(x)) + g(x)

   x     dx

- ℯ  + ─────────────────

               x


In [*34*]: dsolve(eqn, g(x))

Out[*34*]:

                  x

       C₁    x   ℯ

g(x) = ── + ℯ  - ──

       x         x

Then strangely I get:

In [*41*]: dsolve(eqn, g(x)).integrate(x)

Out[*41*]:

            ⌠

            ⎮ ⎛           x⎞

⌠           ⎮ ⎜C₁    x   ℯ ⎟

⎮ g(x) dx = ⎮ ⎜── + ℯ  - ──⎟ dx

⌡           ⎮ ⎝x         x ⎠

            ⌡

But if I just integrate the rhs it does the integral:

In [*40*]: dsolve(eqn, g(x)).rhs.integrate(x)

Out[*40*]:

             x

C₁⋅log(x) + ℯ  - Ei(x)

--
Oscar

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxROOENnFvfstx2ODdTC51JTYfaXgZMz%3DinO8HDKP2pSTA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to