小编use*_*040的帖子

矢量化前向欧拉方法的微分方程组

我正在数值求解一阶微分方程组的x(t).该系统是:

dx/dt = y
dy/dt = -x - a*y(x ^ 2 + y ^ 2 -1)

我已经实现了Forward Euler方法来解决这个问题,如下所示:

def forward_euler():
    h = 0.01
    num_steps = 10000

    x = np.zeros([num_steps + 1, 2]) # steps, number of solutions
    y = np.zeros([num_steps + 1, 2])
    a = 1.

    x[0, 0] = 10. # initial condition 1st solution
    y[0, 0] = 5.

    x[0, 1] = 0.  # initial condition 2nd solution
    y[0, 1] = 0.0000000001

    for step in xrange(num_steps):
        x[step + 1] = …
Run Code Online (Sandbox Code Playgroud)

python numpy vectorization

7
推荐指数
1
解决办法
1873
查看次数

标签 统计

numpy ×1

python ×1

vectorization ×1