Python+Scipyでルンゲクッタ8次のDOP853(Dormand Prince)を使う(その4) ローレンツ96モデル 36変数の方程式
ローレンツ方程式(ローレンツモデル)と言えば3変数のものが有名ですが多変数のローレンツ96というモデルもある。
https://en.wikipedia.org/wiki/Lorenz_96_model
F=8でカオスになるとか。
dx_i/dt=(x_i+1 - x_i-2)*x_i-1 -x_i +F
では計算。Wikipediaではodeintだがdop853で。やっぱりちょっと波形が違うな、、、
プログラムはこちら:
import numpy as np
from scipy.integrate import ode
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
N=36
F=8
def lorenz96(t, x): #odeintのときとt,xの並びが逆
"""Lorenz 96 model."""
# Compute state derivatives
d = np.zeros(N)
# First the 3 edge cases: i=1,2,N
d[0] = (x[1] - x[N-2]) * x[N-1] - x[0]
d[1] = (x[2] - x[N-1]) * x[0] - x[1]
d[N-1] = (x[0] - x[N-3]) * x[N-2] - x[N-1]
# Then the general case
for i in range(2, N-1):
d[i] = (x[i+1] - x[i-2]) * x[i-1] - x[i]
# Add the forcing term
d = d + F
# Return the state derivatives
return d
t0=0.
tmax=30.
dt=0.01
x0 = F * np.ones(N) # Initial state (equilibrium)
x0[19] += 0.01 # Add small perturbation to 20th variable
t = np.arange(t0, tmax, dt)
solver=ode(lorenz96)
solver.set_integrator('dop853')
solver.set_initial_value(x0,t0) #なぜか関数と並びが逆
sol= np.zeros((len(t),N))
sol[0] = x0
k=1
while solver.successful() and solver.t < tmax-dt:
solver.integrate(t[k])
sol[k] = solver.y
k+= 1
# Plot
fig = plt.figure(figsize=(12,12))
ax = fig.gca(projection='3d')
ax.plot(sol[:,0], sol[:,1], sol[:,2])
ax.set_xlabel("X Axis")
ax.set_ylabel("Y Axis")
ax.set_zlabel("Z Axis")
ax.set_title("Lorenz96 Attractor(DOP853)")
plt.show()
« Python+Scipyでルンゲクッタ8次のDOP853(Dormand Prince)を使う(その3) Aizawa Attractor | トップページ | Python+Scipyでルンゲクッタ8次のDOP853(Dormand Prince)を使う(その5) ピタゴラスの三体問題を計算する。rtolとatolを設定しないと無茶苦茶になる。 »
「学問・資格」カテゴリの記事
- 時代に逆行してCOBOL(GnuCOBOL)を学んでみる(6) 31桁の10進演算で複素数を計算するライブラリを作ってみる。外部ファイルのサブルーチンを呼び出すCALL文とUSINGの練習。(2023.06.07)
- 原著で持っているダンズモアさんのHandbook of Microwave Component Measurements With Advanced VNA Techniques(2nd ed.) が邦訳されてマイクロ波部品測定ハンドブック(第2版)として出版されてる!Pozarさんのマイクロ波工学に続き、最近名著の翻訳が増えてるのはいい傾向!(2023.06.03)
- 平均が0でなく相関がある正規分布の比(商)Z=X/Yの分布 Fieller-Hinkleyの式(平均が0ならコーシー分布)をカシオの高精度計算サイトkeisan.casio.jpにあげていたが式にミスがあったのでやり直し。Pythonでモンテカルロして全然違う値になったのでもっと新しい論文探した。(2023.06.02)
- 時代に逆行してCOBOL(GnuCOBOL)を学んでみる(5) 中二病のような名前のブルースカイカタストロフィ(Blue-sky catastrophe)を生じるGavrilov Shilnikov modelをドルマン・プリンス法(ode45)で計算する。テキストベース(アスキーアート)で!(2023.06.01)
- TensorFlow(Keras)でモデルをsaveで保存してload_modelで読み込むときに突然エラー(utf8で読めないとかディレクトリが存在しないとか)が出始めた。なんで?といろいろやると、単に日本語がフォルダ名に使われているときにエラーになるだけだった…(Windowsネイティブの場合)(2023.05.28)
« Python+Scipyでルンゲクッタ8次のDOP853(Dormand Prince)を使う(その3) Aizawa Attractor | トップページ | Python+Scipyでルンゲクッタ8次のDOP853(Dormand Prince)を使う(その5) ピタゴラスの三体問題を計算する。rtolとatolを設定しないと無茶苦茶になる。 »
コメント