« Python+Scipyでルンゲクッタ8次のDOP853(Dormand Prince)を使う(その3) Aizawa Attractor  | トップページ | Python+Scipyでルンゲクッタ8次のDOP853(Dormand Prince)を使う(その5) ピタゴラスの三体問題を計算する。rtolとatolを設定しないと無茶苦茶になる。 »

2020年6月30日 (火)

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で。やっぱりちょっと波形が違うな、、、

Lorenz96

 

プログラムはこちら:

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を設定しないと無茶苦茶になる。 »

学問・資格」カテゴリの記事

コメント

コメントを書く

(ウェブ上には掲載しません)

« Python+Scipyでルンゲクッタ8次のDOP853(Dormand Prince)を使う(その3) Aizawa Attractor  | トップページ | Python+Scipyでルンゲクッタ8次のDOP853(Dormand Prince)を使う(その5) ピタゴラスの三体問題を計算する。rtolとatolを設定しないと無茶苦茶になる。 »

最近の記事

最近のコメント

2023年6月
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
フォト
無料ブログはココログ