[Python] why sympy dsolve gives same series solution for different expansion points?

Discussão em 'Python' iniciado por Stack, Fevereiro 19, 2025.

  1. Stack

    Stack Membro Participativo

    I am learning sympy dsolve. I noticed sometimes it gives same exact series solution regardless of the expansion point given. In sympy expansion point is given using x0=

    So I guess I am doing something wrong?. Is it possible to change the command to obtain same result as Maple's?

    Below is an example.

    This is first order ode. I asked for series solution of the ode and changed x0 from 0 then 1 then 2 then 3, and same result was returned.

    No initial conditions are used.

    I also show below Maple's solution for the same input and we see the result must be different for different expansion point.

    What is the correct way to do this in sympy? I am using python


    Python 3.13.1 (main, Dec 4 2024, 18:05:56) [GCC 14.2.1 20240910] Sympy version 1.13.3
    ​

    Here is the complete code used

    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')
    >>> dsolve(Eq(diff(y(x),x)+x,0),y(x),hint='1st_power_series',x0=0)
    Eq(y(x), -x**2/2 + C1 + O(x**6))

    >>> dsolve(Eq(diff(y(x),x)+x,0),y(x),hint='1st_power_series',x0=1)
    Eq(y(x), -x**2/2 + C1 + O(x**6))

    >>> dsolve(Eq(diff(y(x),x)+x,0),y(x),hint='1st_power_series',x0=2)
    Eq(y(x), -x**2/2 + C1 + O(x**6))

    >>> dsolve(Eq(diff(y(x),x)+x,0),y(x),hint='1st_power_series',x0=3)
    Eq(y(x), -x**2/2 + C1 + O(x**6))


    You see, same answer each time. Here is the same thing in Maple

    restart;
    dsolve(diff(y(x),x)+x=0,y(x),'series',x=0):
    lprint(%);
    y(x) = y(0)-1/2*x^2

    dsolve(diff(y(x),x)+x=0,y(x),'series',x=1):
    lprint(%);
    y(x) = y(1)-x+1-1/2*(x-1)^2

    dsolve(diff(y(x),x)+x=0,y(x),'series',x=2):
    lprint(%);
    y(x) = y(2)-2*x+4-1/2*(x-2)^2

    dsolve(diff(y(x),x)+x=0,y(x),'series',x=3):
    lprint(%);
    y(x) = y(3)-3*x+9-1/2*(x-3)^2

    Continue reading...

Compartilhe esta Página