I'm trying to solve a differential equation using SymPy in Python. I have two solutions x(t)
and y(t)
, but when I try to multiply these solutions by an integer or float, I get this error: "unsupported operand type(s) for *: 'Equality' and 'float'"
from sympy import symbols, Function, Eq, diff, dsolve, solve
def model():
t = symbols('t')
y, x = symbols("y x", cls=Function)
eq = (Eq(diff(y(t), t), (2 * x(t))), Eq(diff(x(t), t), (2 * y(t))))
h = dsolve(eq)
t0 = 0
x0 = 1
y0 = 1
init1 = h[0].rhs.subs(t, t0) - x0
init2 = h[1].rhs.subs(t, t0) - y0
S = solve((init1, init2))
h0 = [h[0].subs(S), h[1].subs(S)]
for i in range(len(h0)):
print(2 * h0[i])
model()
isympy
. That way I can see whath
is, andinit1
, and most relevant to this error,h0
. I'm not enough of asympy
whiz to accurately run the code in my head! – hpaulj