0
這個代碼是否可用?runge kutta第二種方法的python代碼是什麼?
def rKN(x, fx, n, hs):
k1 = []
k2 = []
k3 = []
k4 = []
xk = []
for i in range(n):
k1.append(fx[i](x)*hs)
for i in range(n):
xk.append(x[i] + k1[i]*0.5)
for i in range(n):
k2.append(fx[i](xk)*hs)
for i in range(n):
xk[i] = x[i] + k2[i]*0.5
for i in range(n):
k3.append(fx[i](xk)*hs)
for i in range(n):
xk[i] = x[i] + k3[i]
for i in range(n):
k4.append(fx[i](xk)*hs)
for i in range(n):
x[i] = x[i] + (k1[i] + 2*(k2[i] + k3[i]) + k4[i])/6
return x
考慮是否行得通?你怎麼知道的? –
查看https://stackoverflow.com/questions/35071393/runge-kutta-code-not-converging-with-builtin-method(或側欄上的任何「相關」鏈接)以獲得更緊湊的RK4代碼。 – LutzL