admin管理员组

文章数量:1245084

I am learning sympy dsolve. I find that it gives same solution when using hint='2nd_power_series_ordinary' regardless if initial conditions are given or not.

i.e. it does not replace the C1 and C2 from the IC.

I have not checked series solutions for first order yet if it does the same or not.

Am I doing something wrong or is this just limitation of dsolve?

>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(4*y(x) + Derivative(y(x), (x, 2)),0)
>>> dsolve(ode , y(x),hint='2nd_power_series_ordinary')
Eq(y(x), C2*(2*x**4/3 - 2*x**2 + 1) + C1*x*(1 - 2*x**2/3) + O(x**6))
>>> dsolve(ode , y(x),ics={y(0):0,diff(y(x),x).subs(x,0):3},hint='2nd_power_series_ordinary')
Eq(y(x), C2*(2*x**4/3 - 2*x**2 + 1) + C1*x*(1 - 2*x**2/3) + O(x**6))
>>> 

The correct result should be as follows

ode:=4*y(x)+diff(y(x),x$2)=0;
dsolve(ode,y(x),'series');
collect(convert(%,polynom),[y(0),D(y)(0)])

Which gives

 y(x) = (1 - 2*x^2 + 2/3*x^4)*y(0) + (x - 2/3*x^3 + 2/15*x^5)*D(y)(0)

In the above, y(0) and D(y)(0) (which is y'(0)) are basically what sympy calls C1 and C2.

Now, with IC:

 dsolve([ode,y(0)=0,D(y)(0)=3],y(x),'series')

gives

  y(x) = 3*x - 2*x^3 + 2/5*x^5 + O(x^6)

You see, there should be no C1 and C2 in the solution when IC are given ofcourse.

Is there a workaround (other than having to solve for the C's myself) to have dsolve return the solution without the C's when given initial conditions?

本文标签: pythonwhy sympy dsolve ignores initial conditions with series solutionStack Overflow