我正在数值求解一阶微分方程组的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)