ヘディングのテキスト### 前提
プログラミング初心者です。知識の乏しさゆえ変なことを聞いていたらすいません。。
自分の環境は、macbook pro(2019年購入)、コードは「colaboratory」というサイトで書こうとしています。
コードを書くところがcolaboratoryである必要はないのですが、最終的に.ipynbファイルにできるものが必要で、使っています。
Matplotlibのインストールはおそらくできています。
写真に従い、バージョンが出力されたので
『』
実現したいこと
最終的には下記サイトの真ん中くらいにあるような、シミュレーション動画を作りたいです。
https://qiita.com/jabberwocky0139/items/e2526fc5ee3b0dbf144b
まんまcolaboratoryにコピーペーストしてもサイトのような動画の出力はできなかったので、色々足したりしましたがエラーが出ます、
発生している問題・エラーメッセージ
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-4-bc304a89546d> in <module> 41 42 ---> 43 ani = animation.ArtistAnimation(x,v) 44 rc('animation', html='jshtml') # 追加 45 ani 1 frames /usr/local/lib/python3.8/dist-packages/matplotlib/animation.py in __init__(self, fig, interval, repeat_delay, repeat, event_source, *args, **kwargs) 1431 # sharing timers between animation objects for syncing animations. 1432 if event_source is None: -> 1433 event_source = fig.canvas.new_timer() 1434 event_source.interval = self._interval 1435 AttributeError: 'numpy.ndarray' object has no attribute 'canvas'
該当のソースコード
python
1```import numpy as np 2from scipy.integrate import odeint 3from matplotlib import animation, rc # 追加 4 5 6def trafficJam(f, t, a, c, L): 7 """ 8 微分方程式の定義(odeint) 9 f = [x, v] 10 """ 11 x, v = f[:N], f[N:] 12 13 def V(h): 14 return np.tanh(h - c) + np.tanh(c) 15 16 x_dot = v 17 x = np.append(x, [x[0]]) 18 diff_x = np.diff(x) 19 diff_x = np.array([i if i > 0 else L + i for i in diff_x]) 20 21 v_dot = a * (V(diff_x) - v) 22 23 return np.append(x_dot, v_dot) 24 25 26# 各定数 27N, a, c, L = 30, 1.3, 2, 60 28 29# 初期位置 30x = np.arange(N) * L / N 31 32# 初期速度 33v = [(1 + np.tanh(c)) / 2] + ([1 + np.tanh(c)] * (N - 1)) # 最初の1台がブレーキをかける 34 35# 時刻 36t = np.arange(0, 200, 0.1) 37 38# 微分方程式を解く 39var = odeint(trafficJam, np.append(x, v), t, args=(a, c, L), full_output=False) 40x_arr, v_arr = var[:, :N], var[:, N:] 41 42 43ani = animation.ArtistAnimation(x,v) 44rc('animation', html='jshtml') # 追加 45ani 46
試したこと
色々サイトを調べてみたのですがわかりませんでした、すいません。。。
補足情報(FW/ツールのバージョンなど)
・ここにより詳細な情報を記載してください。
以下は背景です、
最終目標の、シミュレーションの動画を作りたいのは以下の数理モデルです。
時間微分は4次のルンゲクッタ法で求めるというもの。
ソースコードは.py ファイルもしくは.ipynb
動画はmp4形式にしたいです。
あなたの回答
tips
プレビュー