• 検索結果がありません。

数値シミュレーションの基礎 オイラー法とルンゲ・クッタ法

N/A
N/A
Protected

Academic year: 2021

シェア "数値シミュレーションの基礎 オイラー法とルンゲ・クッタ法"

Copied!
28
0
0

読み込み中.... (全文を見る)

全文

(1)

数値シミュレーションの基礎 オイラー法とルンゲ・クッタ法

黒田紘敏(理学研究院 数学部門)

数理解析学特論A /フロンティア数理物質科学II 第7

2020年6月25日

数理解析学特論A (第 回) 数値シミュレーションの基礎

(2)

Introduction

今日は常微分方程式について扱う.有名な微分方程式は,ニュートンの 運動方程式

md2x(t)

d t2 = F(x(t)) などがある.

常微分方程式の解の存在を示すことは一般的に難しくないが,その具体 的な解表示を得ることは難しいことが多い.

(It is not so difficult to show the existence of a solution to an ordinary differential equation. However, it is generally more difficult to express the solutions specifically.)

(Example) 例えば,次の微分方程式

x(t)= x(t)+ex(t)sinx(t), x(0)= 1. の解を x(t) =· · · の形で具体的に示すのは難しい(と思う).

数理解析学特論A (第 回) 数値シミュレーションの基礎

(3)

Contents

Aim

解の具体的な表示が得られないときに,PCによるシミュレーションでそ のグラフの概形を描く方法を学ぶ.そのための数値計算の基本的な考え 方と,オイラー法や自然科学分野で広く用いられているルンゲ・クッタ 法と呼ばれる有名な計算法を理解する.

(When the solution cannot be shown specifically, learn how to draw the outline of the graph by numerical simulation on a PC. To understand the basic concepts of numerical computation and the famous Euler’s method and the Runge-Kutta method, which is widely used in the natural

sciences.)

1 Introduction

2 常微分方程式の解の一意性(Uniqueness of solutions to ODEs)

3 数値計算のアイデア(Idea of Numerical calculations)

4 オイラー法(Euler’s method)

5 ルンゲ・クッタ法(Runge–Kutta method)

数理解析学特論A (第 回) 数値シミュレーションの基礎

(4)

ODE

今日は次のような形の常微分方程式(ODE)を扱う.

dx(t)

d t = f(t,x(t)) (t >0), x(0) = a

ここで,f(t,x)は既知の関数(given function),実数 aは初期値(initial

data)である.変数を省略して

dx

d t = f(t,x) or x = f(t,x) のようにも表す.

(Example)

f(t,x) = x =⇒ dx(t) d t = x(t) f(t,x) =−t x2 =⇒ dx(t)

d t =−t x(t)2

数理解析学特論A (第 回) 数値シミュレーションの基礎

(5)

Review

Example 1

Find the solution to the following ODE: dx

d t = x, x(0)= 1.

Answer

両辺を xで割ってから積分すれば

∫ 1

x dx d t d t =

d t =⇒ log|x|= t+C

となる(Cは積分定数).これを式変形すれば

|x|= et+C =⇒ x(t)= ±eCet = Aet (A=±eC)

となる.ここで,x(0) = A=1なので,求める解はx(t)= et となる.

(Remark) この解は時間大域的に t ≧0の範囲で存在する.

(This is the time global solution on[0,∞).)

数理解析学特論A (第 回) 数値シミュレーションの基礎

(6)

Review

Example 2

Find the solution to the following ODE: dx

d t =2t x2, x(0)=1.

Answer

両辺を x2で割ってから積分すれば

∫ 1

x2 dx d t d t =

2t d t =⇒ −1

x = t2+C =⇒ x(t) =− 1 t2+C となる(Cは積分定数).ここで,初期条件より定数を決定すれば

x(0) =−1

C =1 =⇒ C =−1 ∴ x(t) = 1 1− t2 (Remark) この解は0≤ t< 1の範囲で存在する(解の爆発現象).

(This solution blows up in finite time.)

数理解析学特論A (第 回) 数値シミュレーションの基礎

(7)

Review

Problem 1

Find the solution to the following ODE: dx

d t =−2t x, x(0)= 1.

数理解析学特論A (第 回) 数値シミュレーションの基礎

(8)

Review (Appendix)

Example 3

Find the solution to the following ODE: dx d t = √

x, x(0)= 0.

Answer

x >0として,両辺を √

xで割ってから積分すれば

∫ 1

x dx

d t d t =

d t =⇒ 2√

x = t+C =⇒ x(t) = (t+C)2 4

となる.ここで x(0)=C2/4 =0より,x(t) = t2/4となる.

一方,x(t)= 0 (t≧ 0)は明らかに方程式をみたし,これも解である.

(Remark) 一般に無条件では解の一意性は成り立たない.

(In general, the uniqueness of the solutions does not hold.)

数理解析学特論A (第 回) 数値シミュレーションの基礎

(9)

Idea of Numerical calculations(数値シミュレーションの考え方)

dx(t)

d t = f(t,x(t)) (t >0), x(0) = a

Motivation

微分計算を四則演算で置き換える.

(Replacing differential calculations with four arithmetic operations.)

Reason

PCを使えば四則演算や反復計算については容易に実行できる.

(Four arithmetic operations and iterations can be easily performed in numerical simulations.)

h >0が十分小さければ,導関数の定義より dx(t)

d t = lim

h0

x(t+h)x(t)

hx(t+h)x(t)

h for 0 < h≪1

と期待できる.

数理解析学特論A (第 回) 数値シミュレーションの基礎

(10)

Discretization(離散化)

dx(t)

d t = f(t,x(t)) (t >0), x(0) = a

最初に 時間変数tに関する離散化を行う.0< h≪ 1を1つ固定し t0 =0, tn+1 = tn+h (n=0,1,2, . . .)

とおく.当然ながら

tn= nh (n=0,1,2, . . .) である.

t t

1

t

2

t

3

t

4

t

5

t

0

=0

h h h h h

数理解析学特論A (第 回) 数値シミュレーションの基礎

(11)

Euler’s method

dx(t)

d t = f(t,x(t)) (t >0), x(0) = a x(t)を上の微分方程式の解とする.(Letx(t)be a solution.) x(t) t= tnにおける微分係数の定義より

dx

d t(tn) = lim

h0

x(tn+h)x(tn)

hx(tn+h)x(tn) h

となる.さらに,tn+1 = tn+hなので,微分方程式と合わせて f(tn,x(tn))= dx

d t(tn)≒ x(tn+1)−x(tn) h が得られる.ゆえに

x(tn+1) ≒ x(tn)+hf(tn,x(tn)). という(導関数を含まない)近似式が得られた.

数理解析学特論A (第 回) 数値シミュレーションの基礎

(12)

Euler’s method

Euler’s method

近似式において,“≒を等式にして得られる漸化式

x0 = a, xn+1 = xn+hf(tn,xn) (n=0,1,2, . . .) により数列{xn}を定める.

(In the approximation, the sequence{xn}is determined by a reduction formula obtained by making≒an equal sign.)

このとき,第 nxnは未知関数x(t)t= tnにおける値x(tn)に近い と考えられる.

(In this case, thenth termxnis considered to be an approximation of the valuex(tn).)

Remark

f(tn,xn)が“t = tnにおける接線の傾き”のような役割を果たしている.

(f(tn,xn)plays a role like the slope of the tangent at t = tn.)

数理解析学特論A (第 回) 数値シミュレーションの基礎

(13)

Euler’s method

Euler’s method

x0 = a, xn+1 = xn+hf(tn,xn) (n=0,1,2, . . .)

t t

1

t

2

t

3

t

4

t

5

t

0

=0

h h h h h

x

a x

1

x(t

1

) x(t)

x=a+hf(0,a)

(Remark) 私たちには解 x(t)の本当のグラフはわからない.そこで,

x(0)の代わりに f(t0,x0) = f(0,a)の値を傾きとして採用している.

数理解析学特論A (第 回) 数値シミュレーションの基礎

(14)

Euler’s method

Euler’s method

x0 = a, xn+1 = xn+hf(tn,xn) (n=0,1,2, . . .)

t t

1

t

2

t

3

t

4

t

5

t

0

=0

h h h h h

x

a x

1

x(t

2

) x(t) x

2

x=f(t

1

,x

1

)(t-t

1

)+x

1

(Remark) 私たちには 真の値x(t1)はわからない.そこで,x(t1) ≒ x1と みて f(t1,x1)の値を傾きとしている.

数理解析学特論A (第 回) 数値シミュレーションの基礎

(15)

Euler’s method (Example)

dx(t)

d t = −2t x(t) (t >0), x(0)= a

上の微分方程式にオイラー法を適用すると,f(t,x) =−2t xより xn+1 = xn+hf(tn,xn)= xn−2tnxnh=(1−2nh2)xn

となる.例えば,初期値をa = x0 =10,刻み幅をh=0.1とすれば x1 =(1−2·0·0.12)x0 =10

x2 =(1−2·1·0.12)x1 =9.8 x3 =(1−2·2·0.12)x2 =9.408 x4 =(1−2·3·0.12)x3 =8.84352 x5 =(1−2·4·0.12)x4 =8.136038 と順次 xnが構成できる.

数理解析学特論A (第 回) 数値シミュレーションの基礎

(16)

Euler’s method (Example)

数理解析学特論A (第 回) 数値シミュレーションの基礎

(17)

Euler’s method

Advantage

オイラー法によるコンピューターシミュレーションは難しくない.実際,

オイラー法は xnから xn+1を求めるのに四則演算や代入計算を繰り返す だけだからである.微分方程式の近似解を見つけるために,微分や積分 の計算がまったく現れないことには注意してほしい.

(The sequencexnis determined sequentially, and differential and integral calculations are not used to find approximate solutions to the differential equations.)

Problem

微分方程式の解 x(t)がわからないときに,求めた近似値xnと真の値 x(tn)の誤差を見積もることはできるか?もし可能ならばどのようにすれ ばよいか?

(When the solutionx(t)to a differential equation is not known, can we estimate the error between the approximate value xnand the true value x(tn)? If so, how can we do it?)

数理解析学特論A (第 回) 数値シミュレーションの基礎

(18)

オイラー法の誤差評価(error estimation) x(t)t= tnのまわりでTaylor展開すれば

x(tn+1) = x(tn+h)

= x(tn)+x(tn)h+ x′′(tn)

2 h2+ x′′′(tn)

6 h3+· · ·

= x(tn)+x(tn)h+O(h2) (h→0) となる.

(Remark)

|h| ≪ 1とする(ex. h=102).n≥2, an, 0のとき a2h2+a3h3+a4h4+· · ·+anhn

= h2(a2+a3h+a4h2+· · ·+anhn2)

h2(a2+0)= a2h2

このようにa2h2+a3h3+a4h4+· · · hについて少なくとも2次の微 小量なのでO(h2) (h →0)と表す.

数理解析学特論A (第 回) 数値シミュレーションの基礎

(19)

Consideration of Error

dx(t)

d t = f(t,x(t)) (t >0), x(0) = a

Euler’s method

x0 = a, xn+1 = xn+hf(tn,xn) (n=0,1,2, . . .) 上の微分方程式の解x(t) t= tnのまわりでTaylor展開すれば

x(tn+1) = x(tn)+x(tn)h+O(h2)

= x(tn)+hf(tn,x(tn))+O(h2) (h→0)

となる.よって,漸化式で1ステップ進むのにO(h2)の項を無視してい るので,その程度の誤差は生じうる.

 もし x(t)t =2での値を近似計算しようと思えば,刻み幅がhなら ば2/hステップの計算が必要となる.誤差は累積するから,この場合の 誤差は大雑把に見ればO(h2)×2/h=O(h)程度となる.これよりオイ ラー法は精度よい計算法とはいえない.どう改良すればよいか?

数理解析学特論A (第 回) 数値シミュレーションの基礎

(20)

Error estimate of Euler’s method

Assumption (Lipschitz condition)

ある定数L >0が存在して

|f(t,x)f(t,x)˜ | ≤ L|xx˜|

がすべての t,x,x˜ について成り立つ.これはリプシッツ条件と呼ばれる.

x0 = a, xn+1 = xn+hf(tn,xn) (n=0,1,2, . . .) Taylor展開の式より

x(tn+1) = x(tn)+hf(

tn,x(tn))+O(h2) (h→0) なので,漸化式を引いて誤差を評価すれば

|x(tn+1)−xn+1| ≤ |x(tn)−xn|+h|f(

tn,x(tn))− f(tn,xn)|+O(h2)

≤ (1+Lh)|x(tn)−xn|+Ah2 となる.ただし,Aはある正の定数.

数理解析学特論A (第 回) 数値シミュレーションの基礎

(21)

Error estimate of Euler’s method

これより,x(t0) = a= x0と合わせて

|x(tn)−xn| ≤ (1+Lh)|x(tn1)−xn1|+ Ah2

≤ (1+Lh)2|x(tn−2)−xn−2|+ Ah2+(1+Lh)Ah2

≤ · · ·

≤ (1+Lh)n|x(t0)−x0|

+ Ah2{1+(1+Lh)+· · ·+(1+Lh)n1}

= 0+ Ah2(1+Lh)n−1

(1+Lh)−1 = Ah(1+Lh)n−1 L

が成り立つ.そこで,C= A/Lとおけば,不等式1+xexにより

|x(tn)−xn| ≤Ch{(1+Lh)n−1} ≤Ch(eLtn−1) とわかる.従って,大域的な誤差はO(h)と評価できる.

数理解析学特論A (第 回) 数値シミュレーションの基礎

(22)

Taylor expansion of a solutionx(t)

x(t)t= tnのまわりのTaylor展開で2次の項まで残せば x(tn+1) = x(tn+h)= x(tn)+x(tn)h+ x′′(tn)

2 h2+ x′′′(tn)

6 h3+· · ·

= x(tn)+ f(tn,x(tn))h+ x′′(tn)

2 h2+O(h3) となる.これを基本アイデアとした計算法がホイン法である.

実際には,x′′(tn)を刻みの両端の微分係数を用いて近似し,オイラー法 を援用して次のように漸化式を定める.

x(tn+1) = x(tn)+ h

2{x(tn)+x(tn+ h)}+O(h3)

= x(tn)+ h

2{f(tn,x(tn))+ f(tn+1,x(tn+1))}+O(h3)

x(tn)+ h 2{f(

tn,x(tn))+ f(

tn+1,x(tn)+hf(

tn,x(tn)))}

数理解析学特論A (第 回) 数値シミュレーションの基礎

(23)

Heun’s method(ホイン法)

ホイン法は通常次のように書かれる.

Heun’s method







k1 = f(tn,xn)

k2 = f(tn+h,xn+hk1) xn+1 = xn+h k1+k2

2

t xn

tn

xn+hk1

k2

xn+1

(k1+k2)/2 k1

x k2

tn+1

数理解析学特論A (第 回) 数値シミュレーションの基礎

(24)

The Runge-Kutta method(ルンゲ・クッタ法)

The Runge-Kutta method

x0 = a, tn= nhand forn=0,1,2, . . .















k1 = f(tn,xn) k2 = f(tn+ h

2,xn+ h 2k1) k3 = f(tn+ h

2,xn+ h 2k2) k4 = f(tn+h,xn+hk3)

xn+1 = xn+h k1+2k2+2k3+k4 6

ルンゲ・クッタ法は4次の項まで残した計算法で,1ステップの誤差は O(h5)程度である.そのため,大域的な誤差はO(h4)程度となる.

数理解析学特論A (第 回) 数値シミュレーションの基礎

(25)

The Runge-Kutta method(ルンゲ・クッタ法)

t

t

n

t

n+1

k

1

k

2

h/2 h/2

x

n

+hk

3

x

x

n+1

k

4

(k

1

+2k

2

+2k

3

+k

4

)/6

k

3

x

n

+hk

2

/2

x

n

+hk

1

/2 x

n

数理解析学特論A (第 回) 数値シミュレーションの基礎

(26)

The Runge-Kutta methodexample

数理解析学特論A (第 回) 数値シミュレーションの基礎

(27)

Conclusion

Euler’s method Heun’s method

The Runge-Kutta method

 数値計算法は今日紹介した以外にも多数あるので,精度とコストのバ ランスを考えなければならない.個人的には自然科学分野においてはル ンゲ・クッタ法が広く使われている印象はある.

 微分方程式の解の存在や一意性,および近似による誤差についてはシ ミュレーション結果だけではわからない.そのため,数値計算の妥当性 を保証するための数学の重要性が増しつつあるように思う.

(Since there are many other numerical methods besides the ones introduced today, a balance between accuracy and computational complexity must be considered. I have the impression that the

Runge-Kutta method is widely used in the natural sciences.The numerical simulation results alone do not tell us whether the solution to the

differential equation exists or not, the uniqueness of the solution, or the error of the approximation. Therefore, the importance of mathematics in ensuring the validity of numerical calculations seems to be increasing.)

数理解析学特論A (第 回) 数値シミュレーションの基礎

(28)

References

数値シミュレーションの文献は多数あるが,例えば

E. Kreyszig著,田村義保 訳,技術者のための高等数学5 数値解析

(原書第8版),培風館, 2003.

伊理正夫・藤野和建,数値計算の常識,共立出版, 1985.

山崎郭滋,偏微分方程式の数値解法入門,森北出版, 1993.

高見穎郎・河村哲也,東京大学基礎工学双書 偏微分方程式の差分解 法,東京大学出版会, 1994.

Erwin Kreyszig, Advanced Engineering Mathematics (10th Edition), Wiley, 2011.

Kendall E. Atkinson, Weimin Han, and David E. Stewart, Numerical Solution of Ordinary Differential Equations (1st Edition), Wiley, 2009.

数理解析学特論A (第 回) 数値シミュレーションの基礎

参照

関連したドキュメント

Eskandani, “Stability of a mixed additive and cubic functional equation in quasi- Banach spaces,” Journal of Mathematical Analysis and Applications, vol.. Eshaghi Gordji, “Stability

An easy-to-use procedure is presented for improving the ε-constraint method for computing the efficient frontier of the portfolio selection problem endowed with additional cardinality

We study existence of solutions with singular limits for a two-dimensional semilinear elliptic problem with exponential dominated nonlinearity and a quadratic convection non

В данной работе приводится алгоритм решения обратной динамической задачи сейсмики в частотной области для горизонтально-слоистой среды

Finally, in Section 7 we illustrate numerically how the results of the fractional integration significantly depends on the definition we choose, and moreover we illustrate the

Keywords: continuous time random walk, Brownian motion, collision time, skew Young tableaux, tandem queue.. AMS 2000 Subject Classification: Primary:

modular proof of soundness using U-simulations.. &amp; RIMS, Kyoto U.). Equivalence

We provide an efficient formula for the colored Jones function of the simplest hyperbolic non-2-bridge knot, and using this formula, we provide numerical evidence for the