I was following the tutorial at SymPy site on how to solve differential equations, and started with the classic case of finding a function that equals its own derivative, as shown bellow:
from sympy import Function, dsolve, Derivative, symbols
y = Function('y')
x = symbols('x')
result = dsolve(Derivative(y(x), x) - y(x), y(x))
print(result)
It returns the exponential function, as expected:
Python 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.
=================== RESTART: /xxxx/xxxx/xxxxxxxxxx/eq_diff.py ==================
Eq(y(x), C1*exp(x))
Now I had the idea of trying to add a little tweak, to see if I can find some function that behaves like the exponential, but with “inertia” added. By inertia I mean, instead of f(x) equating its derivative at a given x, there’s sort of a delay, and it will equate its derivative only at a further coordinate in the x axis, say, x + k, so the function would equate it’s rate of change with a fixed delay of k units. So I tried to set this new system like:
from sympy import Function, dsolve, Derivative, symbols
y = Function('y')
x, k = symbols('x k')
result = dsolve(Derivative(y(x), x) - y(x + k), y(x))
print(result)
It doesn’t look that different. But now it seems SymPy failed to find an solution. Instead, it appears to just present the initial equation in alternate form, by integrating both sides:
Python 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.
=================== RESTART: /xxxx/xxxx/xxxxxxxxxx/eq_diff.py ==================
Eq(y(x), C1 + Integral(y(k + x), x))
At first I thought perhaps SymPy didn’t find an solution because my idea of an “exponential with inertia” simply doesn’t exist. But pondering a bit, there’s at least one trivial solution it should have found. For example, a constant function y = 0 will equate its own derivative – 0 – at any offset. So now I think I probably didn’t set it properly. So I ask, where did I get it wrong, how can I set SymPy to solve it properly, and does a non-trivial solution for this exponential with inertia function exist?
3