# Solve differential equation algebraically

**URL:** <https://discourse.julialang.org/t/solve-differential-equation-algebraically/106352>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 17, 2023, 7:47am UTC](https://discourse.julialang.org/t/solve-differential-equation-algebraically/106352 "2023-11-17T07:47:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shikil](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@shikil](https://discourse.julialang.org/u/shikil)\
**Post date:** [November 17, 2023, 7:47am UTC](https://discourse.julialang.org/t/solve-differential-equation-algebraically/106352/1 "2023-11-17T07:47:36Z")

</div>

Hi everyone,

I’m looking for a package that can solve differential equation similar to below Sage code:

```julia
sage: y = function('y')(x)
sage: de = diff(y, x) - y* 2 / x
sage: h = desolve(de, y)
sage: show(expand(h))
_C*x^2

```

Thank you for suggestion.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [November 17, 2023, 8:52am UTC](https://discourse.julialang.org/t/solve-differential-equation-algebraically/106352/3 "2023-11-17T08:52:36Z")

</div>

I don’t think so:

> This is a suite for numerically solving differential equations

OP seems to be asking for “algebraic” (symbolic?) solutions here.

For symbolic computing there is

[https://symbolics.juliasymbolics.org/stable/](https://symbolics.juliasymbolics.org/stable/)

in pure Julia and a wrapper around SymPy here:

> **[GitHub - JuliaPy/SymPy.jl: Julia interface to SymPy via PyCall](https://github.com/JuliaPy/SymPy.jl)**
>
> Julia interface to SymPy via PyCall. Contribute to JuliaPy/SymPy.jl development by creating an account on GitHub.

But I’m not sure whether either of them can solve your example.

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [November 17, 2023, 8:55am UTC](https://discourse.julialang.org/t/solve-differential-equation-algebraically/106352/4 "2023-11-17T08:55:11Z")

</div>

You can do it for sure using [`SymPy`](https://github.com/JuliaPy/SymPy.jl):

```julia
julia> using SymPy
julia> @syms x
(x,)
julia> y = sympy.Function("y")
PyObject y
julia> result = dsolve(sympy.Derivative(y(x), x) - 2*y(x)/x)
           2
y(x) = C₁⋅x 

```

However `SymPy` under the hood uses the Python library with the same name. If performance is a concern, there exist a newer Julia-only package (also better integrated with the rest of the Julia eco-system), [`Symbolics.jl`](https://github.com/JuliaSymbolics/Symbolics.jl).  
But I don’t know if `Symbolics` already has algebraic solver for differential equations.

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [November 17, 2023, 9:42am UTC](https://discourse.julialang.org/t/solve-differential-equation-algebraically/106352/5 "2023-11-17T09:42:53Z")

</div>

I had a look on the documentation of both Symbolics.jl and ModellingToolkits.jl, but I could not find anywhere a point if algebraic resolution of simple differential equations is possible with them.  
Whether is the case, I think a note on this should go in the documentation…

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [November 17, 2023, 11:33am UTC](https://discourse.julialang.org/t/solve-differential-equation-algebraically/106352/6 "2023-11-17T11:33:56Z")

</div>

We don’t have a general symbolic differential equation solving function in ModelingToolkit/Symbolics yet. For now, SymPy.jl is the way to go.
