SinceSympy
version 1.2, python Sympy
has implemented the ability to solve for the constants in a simple differential equation, given some initial conditions. I was trying to test out this feature, but keep getting an error that I don't know how to solve.
The documentation indicates the following format for initial conditions, and I tried to follow what was specified in the actual pull request that implemented the feature. Here is the code and the error.
import sympy as sp
t = sp.symbols('t')
x = sp.Function('x')(t)
diffeq = sp.Eq(x.diff(t,t) - x, sp.cos(t))
res = sp.dsolve(diffeq, t, ics={x(0): 0,
x.diff(t).subs(t, 0): 0})
The error is:
Traceback (most recent call last):
File "<ipython-input-20-75c3e1d53138>", line 1, in <module>
res = sp.dsolve(diffeq, t, ics={x(0): 0, sp.diff(x(t), t).subs(t,0): 0})
TypeError: 'x' object is not callable