[Scientific / technical calculation by Python] Solving second-order ordinary differential equations by Numerov method, numerical calculation

Introduction

In scientific and technical calculations, second-order ordinary differential equations that do not include first-order differentials,

$ \frac{d^2 y}{d x^2} + k^2(x)y=S(x) {\tag 1} $

Often appears (such as the one-dimensional Schrodinger equation).

** As a solution to this equation, there is a very simple and efficient algorithm called ** Numerov method **. This method is only first-order more accurate than the fourth-order Runge-Kutta method [1]. ** **

In this article, we will use Python to solve a simple example.


Numerov method

Uniform grid spacing

h = x_{n}-x_{n+1} {\tag 2}

As, the solution by the Numerov method is

$y_{n+1}= \frac{(1-5bh^2)y_n-(1+\frac{1}{2}k^2_{n-1} h^2)y_{n-1}+b(S_{n+1}+10S_n+S_{n-1})}{1+bk^2_{n+1}h^2} + \mathcal{O(h^6)}{\tag 3} $

[1]. In particular, when $ S (x) = 0 $, the one-dimensional [Helmholtz equation](https://ja.wikipedia.org/wiki/%E3%83%98%E3%83%AB%E3%83] % A0% E3% 83% 9B% E3% 83% AB% E3% 83% 84% E6% 96% B9% E7% A8% 8B% E5% BC% 8F), and the solution by the Numerov method is

$y_{n+1}= \frac{(1-5bh^2)y_n-(1+\frac{1}{2}k^2_{n-1} h^2)y_{n-1}}{1+bk^2_{n+1}h^2} + \mathcal{O(h^6)}{\tag 4} $

Will be.


example

$ \frac{d^2 y}{d x^2} = -4 \pi y, y(0)=1, y'(0)=0 {\tag 5} $

Is solved from x = 0 to 1.

The exact solution is

$ y = cos(2\sqrt \pi x){\tag 6} $ Is.

** The Numerov method requires a value of $ y [1] $ in addition to $ y [0] $. ** ** Here, from the forward difference representation of $ y'(0) $, Let $ y'(0) = (y [1] -y [0]) / h = 0 $ and $ y [1] = 1 $.

Also, set $ h = x_ {n} -x_ {n + 1} = 0.005 $


code


"""
Solving second-order ordinary differential equations by the Numerov method

"""
import numpy as np
import matplotlib.pyplot as plt

delta_x=0.005
xL0, xR0  =0, 1
Nx =  int((xR0-xL0)/delta_x)

k2=np.zeros([Nx+1])
k2[:] = 4*np.pi

y=np.zeros([Nx])

#Initial conditions
y[0] = 1
y[1]=1  # y'(0) = (y[1]-y[0])/delta_Evaluate by forward difference with x

def Numerov (N,delta_x,k2,u):  #Development by the Numerov method
    b = (delta_x**2)/12.0
    for i in range(1,N-1):
        u[i+1] = (2*u[i]*(1-5*b*k2[i])-(1+b*k2[i-1])*u[i-1])/(1+b*k2[i+1]) 

                

Numerov(Nx, delta_x, k2, y) #Numerov method solution

# for plot
X= np.linspace(xL0,xR0, Nx)
y_exact = np.cos(2*np.sqrt(np.pi)*X)
plt.plot(X, y,'o',markersize=2,label='Numerov')
plt.plot(X, y_exact,'-',color='red',markersize=0.5,label='Exact')
plt.legend(loc='upper right')
plt.xlabel('X') #x-axis label
plt.ylabel('Y') #y-axis label

plt.show()

result

t.png

The points represent the numerical solution by the Numerov method, and the red line represents the exact solution.


References

[1] Qiita article [Science and technology calculation by Python] Solving one-dimensional Newton equation by the 4th-order Runge-Kutta method

[2] Masanori Abe et al. (Translation), ["Kunin Computer Physics"](https://www.amazon.co.jp/%E8%A8%88%E7%AE%97%E6%A9%9F% E7% 89% A9% E7% 90% 86% E5% AD% A6-Steven-Koonin / dp / 4320032918)

Recommended Posts

[Scientific / technical calculation by Python] Solving second-order ordinary differential equations by Numerov method, numerical calculation
[Numerical calculation method, python] Solving ordinary differential equations by Eular method
[Scientific / technical calculation by Python] Solving ordinary differential equations, mathematical formulas, sympy
[Scientific / technical calculation by Python] Numerical solution of second-order ordinary differential equations, initial value problem, numerical calculation
[Scientific / technical calculation by Python] Solving simultaneous linear equations, numerical calculation, numpy
[Scientific / technical calculation by Python] Solving the boundary value problem of ordinary differential equations in matrix format, numerical calculation
[Scientific / technical calculation by Python] Sum calculation, numerical calculation
[Scientific / technical calculation by Python] Lagrange interpolation, numerical calculation
[Science / technical calculation by Python] Numerical solution of first-order ordinary differential equations, initial value problem, numerical calculation
[Scientific / technical calculation by Python] Numerical solution of one-dimensional and two-dimensional wave equations by FTCS method (explicit method), hyperbolic partial differential equations
[Scientific / technical calculation by Python] Numerical calculation to find the value of derivative (differential)
[Scientific / technical calculation by Python] Solving one-dimensional Newton equation by the 4th-order Runge-Kutta method
[Scientific / technical calculation by Python] Monte Carlo integration, numerical calculation, numpy
[Scientific / technical calculation by Python] Numerical solution of one-dimensional harmonic oscillator problem by velocity Verlet method
[Scientific / technical calculation by Python] Numerical solution of eigenvalue problem of matrix by power method, numerical linear algebra
[Scientific / technical calculation by Python] Inverse matrix calculation, numpy
Solving ordinary differential equations with Python ~ Universal gravitation
[Scientific / technical calculation by Python] Histogram, visualization, matplotlib
[Scientific / technical calculation by Python] Solving (generalized) eigenvalue problem using numpy / scipy, using library
[Scientific / technical calculation by Python] Numerical solution of two-dimensional Laplace-Poisson equation by Jacobi method for electrostatic potential, elliptic partial differential equation, boundary value problem
[Scientific / technical calculation by Python] Numerical solution of one-dimensional unsteady heat conduction equation by Crank-Nicholson method (implicit method) and FTCS method (positive solution method), parabolic partial differential equation
[Scientific / technical calculation by Python] Logarithmic graph, visualization, matplotlib
[Scientific / technical calculation by Python] Polar graph, visualization, matplotlib
[Scientific / technical calculation by Python] Solving one-dimensional Schrodinger equation in stationary state by shooting method (1), well-type potential, quantum mechanics
[Scientific / technical calculation by Python] Solving one-dimensional Schrodinger equation in stationary state by shooting method (2), harmonic oscillator potential, quantum mechanics
[Scientific / technical calculation by Python] Basic operation of arrays, numpy
[Scientific / technical calculation by Python] List of matrices that appear in Hinpan in numerical linear algebra
Solve ordinary differential equations in Python
[Scientific / technical calculation by Python] Vector field visualization example, electrostatic field, matplotlib
[Scientific / technical calculation by Python] 1D-3D discrete fast Fourier transform, scipy
[Scientific / technical calculation by Python] Monte Carlo simulation of thermodynamics of 2D Ising spin system by Metropolis method
[Scientific / technical calculation by Python] Derivation of analytical solutions for quadratic and cubic equations, mathematical formulas, sympy
[Scientific / technical calculation by Python] Fitting by nonlinear function, equation of state, scipy
Numerical calculation of differential equations with TensorFlow 2.0
[Scientific / technical calculation by Python] Calculation of matrix product by @ operator, python3.5 or later, numpy
[Scientific / technical calculation by Python] Analytical solution to find the solution of equation sympy
[Scientific / technical calculation by Python] Plot, visualize, matplotlib 2D data with error bars
[Scientific / technical calculation by Python] Drawing of 3D curved surface, surface, wireframe, visualization, matplotlib
[Scientific / technical calculation by Python] Solving the Schrodinger equation in the steady state in the 3D isotropic harmonic oscillator potential by the matrix method, boundary value problem, quantum mechanics
[Scientific / technical calculation by Python] Plot, visualization, matplotlib of 2D data read from file
[Scientific / technical calculation by Python] Drawing, visualization, matplotlib of 2D (color) contour lines, etc.
[Python] Numerical calculation of two-dimensional thermal diffusion equation by ADI method (alternate direction implicit method)
Numerical calculation of compressible fluid by finite volume method
Solve simultaneous ordinary differential equations with Python and SymPy.
Solving one-dimensional wave equation by finite difference method (python)
[Scientific / technical calculation by Python] List of usage of (special) functions used in physics by using scipy
[Scientific and technical calculation by Python] Drawing of fractal figures [Sierpinski triangle, Bernsley fern, fractal tree]
[Scientific / technical calculation by Python] Wave "beat" and group velocity, wave superposition, visualization, high school physics
Numerical calculation with Python
Python --Differential equation numerical solution Euler method & central difference method & Runge-Kutta method
Scientific / technical calculation by Python] Drawing and visualization of 3D isosurface and its cross section using mayavi
[Science / technical calculation by Python] Comparison of convergence speeds of SOR method, Gauss-Seidel method, and Jacobi method for Laplace equation, partial differential equation, boundary value problem