Differential equations system with SymPy function dsolve?

1,551 views
Skip to first unread message

CasUpg

unread,
Jul 8, 2015, 8:03:35 PM7/8/15
to julia...@googlegroups.com
Hi,
I'm trying SymPy to solve differential equations system but it does not work in Julia. In Python it does. If I write the following in Python:

from sympy import *
t
= symbols('t')
x
= Function('x')
y
= Function('y')
eq
= (Eq(diff(x(t),t), 12*t*x(t) + 8*y(t)), Eq(diff(y(t),t), 21*x(t) + 7*t*y(t)))
dsolve
(eq)

it returns:

[x(t) == C1*x0 + C2*x0*Integral(8*exp(Integral(7*t, t))*exp(Integral(12*t, t))/x0**2, t),
 y
(t) == C1*y0 + C2(y0*Integral(8*exp(Integral(7*t, t))*exp(Integral(12*t, t))/x0**2, t) + exp(Integral(7*t, t))*exp(Integral(12*t, t))/x0)]


But if I type the following in Julia:

julia> versioninfo()
Julia Version 0.3.10
Commit c8ceeef (2015-06-24 13:54 UTC)
Platform Info:
 
System: Linux (i686-linux-gnu)
  CPU
: Intel(R) Celeron(R) CPU B815 @ 1.60GHz
  WORD_SIZE
: 32
  BLAS
: libopenblas (NO_LAPACK NO_LAPACKE DYNAMIC_ARCH NO_AFFINITY Nehalem)
  LAPACK
: liblapack.so.3
  LIBM
: libopenlibm
  LLVM
: libLLVM-3.3


using SymPy
t
, = @syms t
x
, y = symbols("x, y", cls=SymFunction)
eq
= [Eq(diff(x(t),t), 12*t*x(t) + 8*y(t)), Eq(diff(y(t),t), 21*x(t) + 7*t*y(t))]
dsolve
(eq)

it returns:

ERROR: `dsolve` has no method matching dsolve(::Array{Sym,1})


In the SymPy file math.jl, there is only the following definition for dsolve:

dsolve(ex::Sym, fx::Sym) = sympy_meth(:dsolve, ex, fx)



How can I extend it in order to solve differential equations systems?

A try can be found in:


but it returns a wrong answer.

j verzani

unread,
Jul 8, 2015, 8:49:33 PM7/8/15
to julia...@googlegroups.com
The answer is 

dsolve(exs::Vector{Sym};kwargs...) = sympy_meth(:dsolve, exs; kwargs...)

I just added this to the master version and will push to METADATA soon.

j verzani

unread,
Jul 8, 2015, 8:49:35 PM7/8/15
to julia...@googlegroups.com
The answer is 

dsolve(exs::Vector{Sym};kwargs...) = sympy_meth(:dsolve, exs; kwargs...)

I just added this to the master version and will push to METADATA soon.

On Wednesday, July 8, 2015 at 8:03:35 PM UTC-4, CasUpg wrote:

Ismael VC

unread,
Jul 8, 2015, 9:14:10 PM7/8/15
to julia...@googlegroups.com
Thanks, that's great!

CasUpg

unread,
Jul 9, 2015, 1:17:22 PM7/9/15
to julia...@googlegroups.com
Thank you very much!


El miércoles, 8 de julio de 2015, 19:49:33 (UTC-5), j verzani escribió:
Reply all
Reply to author
Forward
0 new messages