SymPy "solves" a differential equation that it should not solve

Here is what I did:

from sympy import * x = symbols("x") y = Function("y") dsolve(diff(y(x),x) - y(x)**x) 

The answer I received ( SymPy 1.0):

 Eq(y(x), (C1 - x*(x - 1))**(1/(-x + 1))) 

But it's not right. Both Mathematica and Maple cannot solve this problem. What's going on here?

+5
source share
1 answer

Error. SymPy considers this Bernoulli equation

 y' = P(x) * y + Q(x) * y**n 

without checking that the exponent n is constant. Therefore, the decision is incorrect.

I raised issue on the SymPy tracker. It will soon be fixed in the version of SymPy , and then in version 1.2. (Aside, 1.0 is a bit old, many things have improved in 1.1.1, although not the same.)

Upon amendment, SymPy recognizes that there is no explicit solution and resortes to the power series method, creating several members of the power series:

 Eq(y(x), x + x**2*log(C1)/2 + x**3*(log(C1)**2 + 2/C1)/6 + x**4*(log(C1)**3 + 9*log(C1)/C1 - 3/C1**2)/24 + x**5*(log(C1)**4 + 2*(log(C1) - 1/C1)*log(C1)/C1 + 2*(2*log(C1) - 1/C1)*log(C1)/C1 + 22*log(C1)**2/C1 - 20*log(C1)/C1**2 + 20/C1**2 + 8/C1**3)/120 + C1 + O(x**6)) 

You do not need to wait until the patch receives this series of power, it can be obtained by providing SymPy a β€œhint”:

 dsolve(diff(y(x), x) - y(x)**x, hint='1st_power_series') 

Works better with the initial condition:

 dsolve(diff(y(x), x) - y(x)**x, ics={y(0): 1}, hint='1st_power_series') 

returns

 Eq(y(x), 1 + x + x**3/3 - x**4/8 + 7*x**5/30 + O(x**6)) 
+7
source

Source: https://habr.com/ru/post/1274572/


All Articles