How to tell sympy dsolve not to solve the ode using series?

54 views
Skip to first unread message

nma%12...@gtempaccount.com

unread,
Mar 3, 2025, 11:50:18 PM3/3/25
to sympy
I am learning sympy dsolve. I find that it sometimes solve the ode using series when not asked to do this.

I know dsolve has hints to ask it to solve using series.

Is there a way to tell dsolve not to use series solution if it can't solve the ode using exact methods?

Here is an example. Using sympy 1.13.1

-----------------------------------
>python
Python 3.13.1 (main, Dec 4 2024, 18:05:56) [GCC 14.2.1 20240910] on linux
Type "help", "copyright", "credits" or "license" for more information.
 
from sympy import *
x = symbols("x")
y = Function("y")
ode = Eq(x*(1 - x)*Derivative(y(x), x) + y(x)*exp(x) + Derivative(y(x), (x, 2)),0)
ics = {}
dsolve(ode,func=y(x),ics=ics)

It gives
  

Eq(y(x), C2*(x**4*exp(2*x)/24 + x**4*exp(x)/12 - x**2*exp(x)/2 + 1) + C1*x*(x**3/12 - x**2*exp(x)/6 - x**2/6 + 1) + O(x**6))

You see, the solution is series solution as it has O(...) at the end even though there is no hint to use series in the command.

Is it possible to do this?

--Nasser

nma%12...@gtempaccount.com

unread,
Mar 4, 2025, 3:47:22 AM3/4/25
to sympy
Fyi, there was a bug report on this same issue 6 years ago

But it is still not fixed?   I also tried 

dsolve(ode,func=y(x),ics=ics,series=False)

And it still returned series solution. This is wrong. It should only return series solution when explicitly asked to.

--Nasser

Aaron Meurer

unread,
Mar 4, 2025, 1:52:47 PM3/4/25
to sy...@googlegroups.com
Yes, this is a known issue. It shouldn't be too difficult to fix, it
just hasn't been done yet.

However, series is currently the last thing that is attempted. So if
you get a series solution, it really means it just doesn't know how to
solve the ode. You can also check this using classify_ode:

>>> classify_ode(ode)
('factorable', '2nd_power_series_ordinary')

"factorable" is a meta-hint that appears for every ODE. And the only
other one is series. So no algorithms are implemented that can solve
this ODE.

Aaron Meurer
> --
> 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 sympy+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/sympy/12b91fe7-68af-4158-b3dc-0e205e84ee76n%40googlegroups.com.

peter.st...@gmail.com

unread,
Mar 4, 2025, 2:35:02 PM3/4/25
to sy...@googlegroups.com
Dear Aaron,

maybe a dumb question from a retired engineer:
'Most' ODEs cannot be solved in closed form anyway - or so I recall.
What is the point of trying to solve symbolically the 'few' that can be solved in closed form?

Thanks,

Peter
To view this discussion visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6Lc0arAiXdA4sLxYOhPVs41ud%2BjwHbq2PcDuTP%2BFrt83g%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages