[Python] workaround for NotImplementedError: Initial conditions produced too many solutions...

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

  1. Stack

    Stack Membro Participativo

    Is there a workaround for this? Using sympy 1.13.3 with python 3.13.1 when trying to solve y'(x)=y(x)^(1/3) with IC y(0)=1 it gives


    NotImplementedError: Initial conditions produced too many solutions for constants
    ​

    Does sympy really not able to solve this, or do I need some option or setting to use? I am new to using sympy for solving ode's. This ode is just quadrature ode, so I expected no problem solving it in sympy.

    Here is complete code


    python Python 3.13.1 (main, Dec 4 2024, 18:05:56) [GCC 14.2.1 20240910] on linux
    ​

    from sympy import *
    x=symbols('x')
    y=Function('y')
    dsolve(Eq(-y(x)**(1/3) + Derivative(y(x), x),0) , y(x), ics={y(0):1})


    It gives

    > Traceback (most recent call last): File "<python-input-4>", line 1,
    > in <module>
    > dsolve(Eq(-y(x)**(1/3) + Derivative(y(x), x),0) , y(x), ics={y(0):1})
    > ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    > File "/usr/lib/python3.13/site-packages/sympy/solvers/ode/ode.py",
    > line 640, in dsolve
    > return _helper_simplify(eq, hint, hints, simplify, ics=ics) File "/usr/lib/python3.13/site-packages/sympy/solvers/ode/ode.py", line
    > 709, in _helper_simplify
    > solved_constants = solve_ics(, [r['func']], cons(s), ics) File "/usr/lib/python3.13/site-packages/sympy/solvers/ode/ode.py",
    > line 817, in solve_ics
    > raise NotImplementedError("Initial conditions produced too many solutions for constants") NotImplementedError: Initial conditions
    > produced too many solutions for constants
    > >>>


    The solution should be

    ode:=diff(y(x),x)=y(x)^(1/3);
    dsolve([ode,y(0)=1])

    # y(x) = (9 + 6*x)^(3/2)/27

    Continue reading...

Compartilhe esta Página