gpt4 book ai didi

python - 在Python中设置颂歌

转载 作者:太空宇宙 更新时间:2023-11-03 18:58:16 24 4
gpt4 key购买 nike

如何在Python中设置以下具有相应初始条件的ode?

x'(t) =x(t) - y(t) - e^t

y'(t) =x(t) + y(t) + 2e^t

with x(0)= -1 and y(0)= -1 and 0 <= t <= 4

以下是我目前所掌握的内容:

def f(u, t):
x, y = u
return [x+y-e**t, x+y+2*e**t]

x0, y0 = [-1.0,-1.0]
t = numpy.linspace( 0,4,50 )

最佳答案

我猜你正在尝试用 odeint 来解决它们。首先,我假设您在脚本中使用了这个前奏:

import numpy as np
from scipy.integrate import odeint

你的等式是:

def equation(X, t):
x, y = X
return [ x+y-np.exp(t), x+y+2*np.exp(t) ]

然后你可以用以下方法解决它们

init = [ -1.0, -1.0 ]
t = np.linpsace(0, 4, 50)
X = odeint(equation, init, t)

您可以使用以下方法提取 x(t) 和 y(t)

x = X[:, 0]
y = X[:, 1]

关于python - 在Python中设置颂歌,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16747624/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com