常微分方程式の数値解法(3)
SciPyのodeintを用いて以下の厳密解のあるOrdinary Differential Equations (ODE)を解き,文献[1]の数値解を再現する.
なお,文献[1]のの右辺第3項の
は
の間違いである.これら常微分方程式の厳密解は以下に示すとおりである.
[1] Thohura, S. and Rahman, A., Numerical Approach for Solving Stiff Differential Equations: A Comparative Study, GLOBAL JOURNAl OF SCIENCE FRONTIER RESEARCH MATHEMATICS AND DECISION SCIENCES, 13 (6) (2013)
# # Thohura, S. and Rahman, A., # Numerical Approach for Solving Stiff Differential Equations: # A Comparative Study, # GLOBAL JOURNAl OF SCIENCE FRONTIER RESEARCH # MATHEMATICS AND DECISION SCIENCES, 13 (6) (2013) # import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # right-hand side def rhs(y, x): return [ 9.0*y[0] + 24.0*y[1] + 5.0*np.cos(x) - np.sin(x)/3.0, -24.0*y[0] - 51.0*y[1] - 9.0*np.cos(x) + np.sin(x)/3.0] # exact solution def exact(x): return [2.0*np.exp(-3.0*x) - np.exp(-39.0*x) + np.cos(x)/3.0, - np.exp(-3.0*x) + 2.0*np.exp(-39.0*x) - np.cos(x)/3.0] # initial condition y0 = [4.0/3.0, 2.0/3.0] # output interval x = np.arange(0.0, 1.0, 0.01) # solve ode y = odeint(rhs, y0, x) #y_e = [[0 for i in range(100)] for j in range(2)] y_e = np.empty((100, 2)) # exact solution i = 0 for t in x: y_e[i,:] = exact(t) i += 1 # output plt.xlabel('t') plt.ylabel('u') plt.plot(x, y_e[:,0],marker='o', markerfacecolor='none',color='blue') plt.plot(x, y_e[:,1],marker='o', markerfacecolor='none',color='orange') plt.plot(x, y[:,0], label='u1', color='blue') plt.plot(x, y[:,1], label='u2', color='orange') plt.legend() #plt.show() plt.savefig('Thohura2013-Fig2.png')