14
Lecture 14 コンピュータその14 1 1. 常微分方程式の数値解法 2. 偏微分方程式の数値解法 Tuesday, January 24, 17

Lecture 14 - 北海道大学mmc01.es.hokudai.ac.jp/.../courses/computer/lec/Lec_14.pdfLecture 14 コンピュータその14 1 1. 常微分方程式の数値解法 2. 偏微分方程式の数値解法

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lecture 14 - 北海道大学mmc01.es.hokudai.ac.jp/.../courses/computer/lec/Lec_14.pdfLecture 14 コンピュータその14 1 1. 常微分方程式の数値解法 2. 偏微分方程式の数値解法

Lecture 14

コンピュータその141

1. 常微分方程式の数値解法

2. 偏微分方程式の数値解法

Tuesday, January 24, 17

Page 2: Lecture 14 - 北海道大学mmc01.es.hokudai.ac.jp/.../courses/computer/lec/Lec_14.pdfLecture 14 コンピュータその14 1 1. 常微分方程式の数値解法 2. 偏微分方程式の数値解法

Lotka-Volterra8><

>:

x

0 = x(a� by)

y

0 = �y(c� dx)

x(0) = 1/10, y(0) = 3 a, b, c, d は正の定数である.

常微分方程式の数値解法 1. 次の Lotka-Volterra 方程式を考える。二種の生物が捕食-被食関

係にある場合の個体数の変化を表す方程式である。

Euler 法により Lotka-Volterra 方程式の数値解を計算し、(t, x(t)),

(t, y(t)) 及び (x(t), y(t)) のグラフを確認せよ。

a = b = c = d = 1 h = 0.01

t > 0

Tuesday, January 24, 17

Page 3: Lecture 14 - 北海道大学mmc01.es.hokudai.ac.jp/.../courses/computer/lec/Lec_14.pdfLecture 14 コンピュータその14 1 1. 常微分方程式の数値解法 2. 偏微分方程式の数値解法

常微分方程式の数値解法ヒント:グラフの描画複数の列からなるデータファイル中の任意の列を表示したい場合、plot の際にオプショ ン using を使う。例えば 3 列からなるデータが書き込まれているファイルから 2 列目の数値を x 軸、三列目の数値を y 軸にとりたいときには

gnuplot> plot "data.dat" using 2:3

複数のグラフを描く場合には,カンマで繋げる。

gnuplot> plot "data.dat" using 1:2, "data.dat" using 1:3

2. 修正 Euler 法で計算と可視化せよ.x

pn+1 = xn + hf(tn, xn)

xn+1 = xn + h2 (f(tn, xn) + f(tn+1, x

pn+1))

Tuesday, January 24, 17

Page 4: Lecture 14 - 北海道大学mmc01.es.hokudai.ac.jp/.../courses/computer/lec/Lec_14.pdfLecture 14 コンピュータその14 1 1. 常微分方程式の数値解法 2. 偏微分方程式の数値解法

Euler法は上の積分の項を矩形で近似して計算したものである.

dx

dt

= f(t, x)

x(t+ h) = x(t) +R t+ht f(s, x(s))ds

常微分方程式の数値解法(修正Euler法とは)

修正Euler法は台形で近似を行う.

xn+1 = xn + h2 (f(tn, xn) + f(tn+1, xn+1))

上の公式は   が含まれているために,このままで計算ができない.そこで,Euler法で近似した値   を求め,その値を用いて計算する.

xn+1

x

pn+1

x

pn+1 = xn + hf(tn, xn)

xn+1 = xn + h2 (f(tn, xn) + f(tn+1, x

pn+1))

Tuesday, January 24, 17

Page 5: Lecture 14 - 北海道大学mmc01.es.hokudai.ac.jp/.../courses/computer/lec/Lec_14.pdfLecture 14 コンピュータその14 1 1. 常微分方程式の数値解法 2. 偏微分方程式の数値解法

van der Pole方程式

常微分方程式の数値解法 3.

x

00(t) = a(1� x(t)2)x0(t)� x(t)

の数値解を求め,(x(t), xʹ′(t)) を描写せよ.初期値を変えて x(t) および xʹ′(t)

の変化を観察せよ.例:

x

00(t) ⇡ x(t+�t)� 2x(t) + x(t��t)

�t

2

ヒント:

x

0(0) ⇡ x(0)� x(��t)

�t

x(0) = 1, x0(0) = 0

Tuesday, January 24, 17

Page 6: Lecture 14 - 北海道大学mmc01.es.hokudai.ac.jp/.../courses/computer/lec/Lec_14.pdfLecture 14 コンピュータその14 1 1. 常微分方程式の数値解法 2. 偏微分方程式の数値解法

ローレンツ方程式 (Lorenz equation) 4.

常微分方程式の数値解法

は大気の状態の変化を記述する偏微分方程式に由来する 3 変数の常微分方程 式である.σ = 10,ρ = 28,β = 8/3 とし,適当な初期値からの解曲線 X(t) = (x(t), y(t), z(t)) を修正 Euler 法で計算し,gnuplot で3次元表示せよ.時間刻み は 0.001,t = 0 から 100 の範囲で計算する.ま

た,初期値からわずかに (< 10−8) 離れた別の初期値からの解 Xˆ(t) と元の解との距離 |X (t) − Xˆ(t)| は,t とともにどの ように広がっていくかを計算し,gnuplot で表示せよ.

8><

>:

x

0 = �(y � x)

y

0 = x(⇢� z)� y

z

0 = xy � �z

gnuplot> splot "butterfly.dat" using 2:3:4 w lTuesday, January 24, 17

Page 7: Lecture 14 - 北海道大学mmc01.es.hokudai.ac.jp/.../courses/computer/lec/Lec_14.pdfLecture 14 コンピュータその14 1 1. 常微分方程式の数値解法 2. 偏微分方程式の数値解法

偏微分方程式の数値解法熱方程式 ポアソン方程式

波動方程式 自由境界問題

Tuesday, January 24, 17

Page 8: Lecture 14 - 北海道大学mmc01.es.hokudai.ac.jp/.../courses/computer/lec/Lec_14.pdfLecture 14 コンピュータその14 1 1. 常微分方程式の数値解法 2. 偏微分方程式の数値解法

u(t, x) : (0, T )⇥ [0, L] ! R

x

t

�x

�t

u(t = 0, x)u(t = �t, x)

x = 0

x = L

偏微分方程式の数値解法

8><

>:

ut = �u in (0,�t)⇥ ⌦

@u@⌫ = 0 on (0,�t)⇥ @⌦

u(t = 0, x) = u0 in ⌦

8

Tuesday, January 24, 17

Page 9: Lecture 14 - 北海道大学mmc01.es.hokudai.ac.jp/.../courses/computer/lec/Lec_14.pdfLecture 14 コンピュータその14 1 1. 常微分方程式の数値解法 2. 偏微分方程式の数値解法

拡散方程式の導出d

dt

Z

Vudx = �

Z

@VF · ⌫dS

ut = �divF

F / ru F = �aru (a > 0)

ut = adiv(ru) = a�u

Z

Vutdx = �

Z

VdivFdx

ut

= uxx

=)1次元

発散定理

=)

=)

=)formally

9

変化率 平均フラックス

=)

Tuesday, January 24, 17

Page 10: Lecture 14 - 北海道大学mmc01.es.hokudai.ac.jp/.../courses/computer/lec/Lec_14.pdfLecture 14 コンピュータその14 1 1. 常微分方程式の数値解法 2. 偏微分方程式の数値解法

時間発展の問題

拡散方程式8><

>:

u

t

= u

xx

(t, x) 2 (0, T )⇥ (0, L)

u(t, 0) = 0, u(t, L) = 0

u(t = 0, x) = u0 x 2 ⌦

u0

uxx

0

uxx

� 0

10

Tuesday, January 24, 17

Page 11: Lecture 14 - 北海道大学mmc01.es.hokudai.ac.jp/.../courses/computer/lec/Lec_14.pdfLecture 14 コンピュータその14 1 1. 常微分方程式の数値解法 2. 偏微分方程式の数値解法

差分法における時間発展問題の近似解法

u(t+�t, x) = u(t, x) + ut(t, x)�t+ utt(t, x)�t

2

2+ ...

ut(t, x) ⇡u(t+�t, x)� u(t, x)

�t

8><

>:

u

t

= u

xx

(t, x) 2 (0, T )⇥ (0, L)

u(t, 0) = 0, u(t, L) = 0

u(t = 0, x) = u0 x 2 ⌦

u

xx

(t, x) ⇡ u(t, x+�x)� 2u(t, x) + u(t, x��x)

�x

2

=)

テイラー展開

11

Tuesday, January 24, 17

Page 12: Lecture 14 - 北海道大学mmc01.es.hokudai.ac.jp/.../courses/computer/lec/Lec_14.pdfLecture 14 コンピュータその14 1 1. 常微分方程式の数値解法 2. 偏微分方程式の数値解法

差分法における拡散方程式の近似解法

5.8><

>:

u

t

= u

xx

(t, x) 2 (0, T )⇥ (0,⇡)

u(t, 0) = 0, u(t,⇡) = 0

u(t = 0, x) = sin(x) x 2 [0,⇡]

差分法を用いて上記の問題における数値解を計算せよ.

dt =�x

2

6ヒント:

u(t+�t, x) = u(t, x) +�t

u(t, x+�x)� 2u(t, x) + u(t, x��x)

�x

2

12

splot ‘heat_sol.dat’ w d0.000000 0.000000 0.0000000.000000 0.080554 0.0803800.000000 0.161107 0.1602380.000000 0.241661 0.2390570.000000 0.322215 0.316326

heat_sol.datt x u

�x = L/99 [0, L] L = ⇡

Tuesday, January 24, 17

Page 13: Lecture 14 - 北海道大学mmc01.es.hokudai.ac.jp/.../courses/computer/lec/Lec_14.pdfLecture 14 コンピュータその14 1 1. 常微分方程式の数値解法 2. 偏微分方程式の数値解法

誤差解析

6.

解:u(t, x) = sin(x)e�t

8><

>:

u

t

= u

xx

(t, x) 2 (0, T )⇥ (0,⇡)

u(t, 0) = 0, u(t,⇡) = 0

u(t = 0, x) = sin(x) x 2 [0,⇡]

数値解の誤差を計算せよ.

t ヒント:

誤差:E(t) = ||u(t, x)� sin(x)e�t||2 =

✓Z ⇡

0(u(t, x)� sin(x)e�t)2dx

◆1/2

E(t)

13

dt =�x

2

6[0, L] L = ⇡�x = L/39

Tuesday, January 24, 17

Page 14: Lecture 14 - 北海道大学mmc01.es.hokudai.ac.jp/.../courses/computer/lec/Lec_14.pdfLecture 14 コンピュータその14 1 1. 常微分方程式の数値解法 2. 偏微分方程式の数値解法

14

Be careful, the explicit method is unstable

�t = 0.0009

�x = 0.04

8><

>:

u

t

= u

xx

(t, x) 2 (0, T )⇥ (0,⇡)

u(t, 0) = 0, u(t,⇡) = 0

u(t = 0, x) = sin(x) x 2 [0,⇡]

7.

差分法を用いて上記の問題における数値解を計算せよ.

“N =40”

Tuesday, January 24, 17