Why does sympy dsolve ignore initial conditions sometimes?

63 views
Skip to first unread message

nma%12...@gtempaccount.com

unread,
Mar 4, 2025, 6:28:27 AM3/4/25
to sympy
I noticed sometimes dsolve ignore IC give and gives general solution instead. This seems to happen when it is not able to resolve the constants of integrations.

In this case it should return no solution instead.

Is there a way to tell it not to do this? Here is an example

>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**2*Derivative(y(x), (x, 2)) - 4*x*Derivative(y(x), x) + 6*y(x),0)
ics = {y(0): 2, Subs(Derivative(y(x), x), x, 2): -1}
dsolve(ode,func=y(x),ics=ics)

It gives  

Eq(y(x), x**2*(C2*x - 3*C2 - 1/4))

Notice the solution contains C2.

Actually there is no solution to this ode with these IC's, so it should not have returned any solution. This is what Maple does

ode:=x^2*diff(y(x),x$2)-4*x*diff(y(x),x)+6*y(x)=0;
IC:=y(0)=2,D(y)(2)=-1;
sol:= dsolve([ode,IC]);

           ( )

i.e. No solution.

--Nasser

Aaron Meurer

unread,
Mar 4, 2025, 1:36:35 PM3/4/25
to sy...@googlegroups.com
It is true that we need to disable returning series solutions by
default. However, this solution is not a power series solution (if it
were, it would contain an order term).

The issue here is that the initial conditions solver in dsolve isn't
handling the initial conditions correctly. I would suggest opening an
issue about this.

As an aside, I've noticed some other bugs related to this ODE: the
2nd_linear_bessel hint gives the wrong answer, and the checkodesol
function should also include an ics flag so it can check initial
conditions.

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/eb80deff-baa8-4026-9a37-8d49c6a8647bn%40googlegroups.com.

Aaron Meurer

unread,
Mar 4, 2025, 1:48:20 PM3/4/25
to sy...@googlegroups.com
On Tue, Mar 4, 2025 at 11:36 AM Aaron Meurer <asme...@gmail.com> wrote:
>
> It is true that we need to disable returning series solutions by
> default. However, this solution is not a power series solution (if it
> were, it would contain an order term).

I think I confused this message with a different one you made on the list.

Aaron Meurer

nma%12...@gtempaccount.com

unread,
Mar 5, 2025, 1:14:07 AM3/5/25
to sympy
"I would suggest opening an issue about this."

I have github user name and pass word. but I can no longer login. After I enter these, it asks me to do some  2FA 
thing.,
 
I do not know how to use smart phone or apps.

I only can use the mouse and keyboard. It wants to scan something on the screen or come up with some code. I have no clue how to do this.

So I will enter sympy bugs here and any one is welcome to enter them in github. Last time I logged to github was a year ago
and can't do it anymore.

--Nasser

Reply all
Reply to author
Forward
0 new messages