#!/usr/bin/env python # coding: utf-8 # ### DyMat を使ってシミュレーション結果を読み込む # DyMat は Dymola や OpenModelica, JModelica.org などの結果ファイル(matファイル)を読み込んだり、他のファイル形式にエクスポートすることができるライブラリです。これを使って JModelica.org によるシミュレーション結果ファイルのデータをプロットします。DyMat の詳細な使用方法は、[Dymat User Manual Dy Mat Guide](https://usermanual.wiki/Pdf/DyMatGuide.1572623990)に記載されています。 # # まず、mat ファイルのリストを表示します。 # In[1]: get_ipython().run_line_magic('ls', '*.mat') # Van der Pole oscillator のシミュレーション結果 VDP_resullt.mat を読み込みます。 # In[2]: import DyMat d = DyMat.DyMatFile('VDP_result.mat') # すべての変数名を表示します。 # In[3]: for name in d.names(): print(name) # アンダーバーから始まる変数名を除いて表示します。 # In[4]: for name in d.names(): if name.find('_') != 0: print(name) # プロットするデータを抽出します。 # In[5]: t = d.abscissa('x1', valuesOnly=True) x1 = d.data('x1') x2 = d.data('x2') # データをプロットします。 # In[6]: get_ipython().run_line_magic('matplotlib', 'notebook') import matplotlib.pyplot as plt plt.figure(1) plt.plot(t, x1, t, x2) plt.legend(( 'x1', 'x2')) plt.title('Van der Pol scillator.') plt.ylabel('Angle (rad)') plt.xlabel('Time (s)') # In[ ]: