在python中设置odes [英] setup odes in python

查看:116
本文介绍了在python中设置odes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在python中使用相应的初始条件设置以下odes?

how to setup the following odes with the corresponding initial conditions in python?

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

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

x(0)= -1y(0)= -10 <= t <= 4

以下是我到目前为止的内容:

The following is what I have so far:

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解决它们.首先,我假设您在脚本中使用了此前奏:

I guess you're trying to solve them with odeint. First I'm assuming you use this prelude in you script :

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)

You can extract x(t) and y(t) with

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

这篇关于在python中设置odes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆