[Python] 2nd ODE with numerical method(3)


[Python] 2nd ODE with numerical method(3)

이번에는 Runge-Kutta method를 이용해서 numerical solution을 구하고 표시해보자. 코드를 짜보면 다음과 같다. import numpy as np import matplotlib.pyplot as plt from scipy.integrate import odeint # 주어진 미분 방정식 def model(y, t): dydt = [y[1], -omega**2 * y[0]] return dydt # Runge-Kutta 2nd order method def runge_kutta2(y0, v0, omega, dt, num_steps): y = np.zeros(num_steps + 1) v = np.zeros(num_steps + 1) y[0] = y0 v[0] = v0 for i in range(num_steps): k1y = dt * v[i] k1v = -dt * omega**2 * y[i] k2y = dt * (v[i] + 0.5 * k1v) k2v = -...


#2nd #kutta #method #numerical #ODE #RK #RK2 #RK4 #runge

원문링크 : [Python] 2nd ODE with numerical method(3)