t, C1, C2= symbols("t C1 C2")
x, y = symbols("x y", cls = Function, Function = True)
eq1 = Eq(3 * diff(x(t), t), y(t))
eq2 = Eq(diff(y(t),t), - 3 * y(t) - 15 * x(t) + 4 * 1)
soln = dsolve((eq1, eq2), ics = {x: 5, y: 0})
soln它工作得很好。然而,
t, C1, C2= symbols("t C1 C2")
x, y = symbols("x y", cls = Function, Function = True)
ics = {x: 5, y: 0}
eq1 = Eq(3 * diff(x(t), t), y(t))
eq2 = Eq(diff(y(t),t), - 3 * y(t) - 15 * x(t) + 4 * 1)
def solve_ode_ivp(eq1, eq2, ics):
soln = dsolve((eq1, eq2), ics)
return soln
solve_ode_ivp(eq1, eq2, ics)给出错误消息TypeError: unhashable type:'dict‘。它在ics上有问题,但我不知道为什么以及如何修改solve_ode_ivp才能正常工作。
发布于 2019-03-31 16:02:01
在第一个版本中输入ics= {x:5 , y: 0}时,您指定可选参数ics将此字典作为值,在第二个版本中,您将其作为第二个参数(不是ics)发送。
您可以将其更改为:
t, C1, C2= symbols("t C1 C2")
x, y = symbols("x y", cls = Function, Function = True)
ics = {x: 5, y: 0}
eq1 = Eq(3 * diff(x(t), t), y(t))
eq2 = Eq(diff(y(t),t), - 3 * y(t) - 15 * x(t) + 4 * 1)
def solve_ode_ivp(eq1, eq2, ics):
soln = dsolve((eq1, eq2), ics=ics)
return soln
solve_ode_ivp(eq1, eq2, ics)https://stackoverflow.com/questions/55438838
复制相似问题