■
本日初めてNISAの積み立て投資を行った。これから毎月3万積み立てて資産形成頑張っていくぞ!
最近の出来事20241125
最近社内の英語の研修を受けたが、題材が「トランスフォーマー」に関するもので懐かしく感じた。当時自分が小学生の頃にトランスフォーマーが上映され男の子なら誰しも共感できると思うが戦闘シーンや変形シーンにはひどく熱がはいった記憶がある。ただ、語り合える友がいなかったのは身近にいなかったのは残念だが。しかし、思えばこの映画をきっかけに機械や人工知能に興味を持ったのだと思うとマイケル・ベイ監督には感謝しきれない。また、映画に使用されたリンキンパークの音楽も魅力的であることに気づき聞きっぱなしであるのだが、メインボーカルのの人がもう何年も前に自殺してしまっていたので早くにこの音楽の魅力に気づいてコンサートに行っておけばよかったと後悔している。
最近の出来事20240922
今年会社に勤めてから半年近くなった。会社で働くことにも慣れ、同期ともそれなりに付き合いがあり幸いにも楽しい日々を送ることができている。そのせいか、ふと自分の人生について考えることがあるのだが、自分が50年後も楽しく幸せに過ごしている未来を想像することができない。その理由は、現在の日本の政治に期待を持てないためである。日本の政治家には一部を除いて愛国心というものがなく、本気で我々のことを思って政治に取り組んでいる人は少数であるかのように感じれられる。反日国家である中国や韓国に取り入ろうとする国賊のせいで、我々が普段当たり前に享受してきた治安や秩序が崩壊していく流れをとめなければならない。未来の日本人のためにも。
JupyterLab上でのアニメーションの出力方法
JupyterLab上でmatplotlibのアニメーションを出力する。
以下に参考URLを記載する。
JupyterLab上でmatplotlibのアニメーションを出力する - Qiita
内容を記述する。(消えると困るので)
方法1:IPython.display.HTMLの使用
確認用のコードを以下に示す
import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation from IPython.display import HTML fig, ax = plt.subplots() xdata, ydata = [], [] ln, = plt.plot([], [], 'ro') def init(): ax.set_xlim(0, 2 * np.pi) ax.set_ylim(-1, 1) return ln, def update(frame): xdata.append(frame) ydata.append(np.sin(frame)) ln.set_data(xdata, ydata) return ln, ani = FuncAnimation(fig, update, frames=np.linspace(0, 2 * np.pi, 128), init_func=init, blit=True, interval=50) HTML(ani.to_jshtml()) # HTML(ani.to_html5_video()) # またはこちら
方法2:jupyter-matplotlibの使用
確認用のコードを以下に示す
import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation %matplotlib widget fig, ax = plt.subplots() xdata, ydata = [], [] ln, = plt.plot([], [], 'ro') def init(): ax.set_xlim(0, 2 * np.pi) ax.set_ylim(-1, 1) return ln, def update(frame): xdata.append(frame) ydata.append(np.sin(frame)) ln.set_data(xdata, ydata) return ln, ani = FuncAnimation(fig, update, frames=np.linspace(0, 2 * np.pi, 128), init_func=init, blit=True, interval=50)
単相インバータ波形(ハーフブリッジ)のpython script
import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as ticker import scipy.signal as signal class Inverter: def __init__(self,N=2**10): self.N=N #サンプリング数 #sin波 def sin_wave(self,Es,f1): x_sin=np.linspace(0,2*np.pi,self.N) y_sin=Es*np.sin(x_sin*f1) return(x_sin,y_sin) #三角波 def tri_wave(self,Et,mf,f1): x_tri=np.linspace(0,2*np.pi,self.N) y_tri=Et*signal.sawtooth(x_tri*mf*f1-np.pi/2,0.5) return(x_tri,y_tri) #方形波 def rectangle_wave(self,x_sin,y_sin,x_tri,y_tri,V): x_rec = x_sin y_rec = np.where(y_sin > y_tri, V/2, -V/2) return (x_rec, y_rec) sin=Inverter() tri=Inverter() rec=Inverter() """ 振幅変調率=sin波の振幅/三角波の振幅=0.8になるようにしている。 周波数変調率=三角波の周波数/sin波の周波数=15になるようにしている。 三角波の振幅はEt=5 Vで変調波の振幅はEs=4 Vである。 電源電圧V=30 Vである。 正弦波の基本周波数f=1 Hzである。 """ ma=0.8 mf=15 Et=5 Es=Et*ma V=30 f1=1 N=2**10 f=1/N #sin波の生成 x_sin,y_sin=sin.sin_wave(Es,f1) x_sin1,y_sin1=sin.sin_wave(V*ma/2,f1) #三角波の生成 x_tri,y_tri=tri.tri_wave(Et,mf,f1) #矩形波の生成 x_rec,y_rec=rec.rectangle_wave(x_sin,y_sin,x_tri,y_tri,V) fft_data = (abs(np.fft.rfft(y_rec)))/(N/2*V/2) #矩形波をフーリエ変換し基本波の振幅との比をとっている。 freqList = np.fft.rfftfreq((len(y_rec)),f) position=[0,np.pi,2*np.pi] #軸の主要値 labels=['0','π','2π'] #軸の主要値の名前 #ax1に三角波とsin波を図示する。 fig1=plt.figure() ax1=fig1.add_subplot() ax1.plot(x_sin,y_sin) ax1.plot(x_tri,y_tri) ax1.set_title("sin wave,tri_wave") #図のタイトル ax1.set_xlabel("phase") #x軸の名前 ax1.set_ylabel("voltage") #y軸の名前 ax1.xaxis.set_major_locator(ticker.FixedLocator(position)) #軸の主要値の場所を指定 ax1.xaxis.set_major_formatter(ticker.FixedFormatter(labels)) #軸の主要値の名前を指定 #ax2に基本波と矩形波を図示する。 fig2=plt.figure() ax2=fig2.add_subplot() ax2.plot(x_sin1,y_sin1,linestyle="dashed") ax2.plot(x_rec,y_rec) ax2.set_title("sin wave,rec wave") #図のタイトル ax2.set_xlabel("phase") #x軸の名前 ax2.set_ylabel("voltage") #y軸の名前 ax2.xaxis.set_major_locator(ticker.FixedLocator(position)) #軸の主要値の場所を指定 ax2.xaxis.set_major_formatter(ticker.FixedFormatter(labels)) #軸の主要値の名前を指定 #ax3に矩形波の高調波成分を図示する。 fig3=plt.figure() ax3=fig3.add_subplot() ax3.plot(freqList,fft_data) ax3.set_title("harmonic of rec wave") #図のタイトル ax3.set_xlabel("frecency") ax3.set_ylabel("power") #y軸の名前 ax3.set_xlim(0.0,100)
以上です。
グラフの書き方(sin波,cos波)
import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as ticker x=np.linspace(0,2*np.pi,1000) #0~2πまで1000個作成 y1=np.sin(x) y2=np.cos(x) fig=plt.figure() #figureを作成 ax1=fig.add_subplot(211) #figure内の2行1列1番目にax1を作成 ax2=fig.add_subplot(212) #figure内の2行1列2番目にax2を作成 ax1.plot(x,y1) #sin波作成 ax2.plot(x,y2) #cos波作成 #図の体裁を整えていく position=[0,np.pi,np.pi*2] #軸の主要値 labels=['0','π','2π'] #軸の主要値の名前 ax1.set_title("sin wave") #図のタイトル ax1.set_xlabel("phase") #x軸の名前 ax1.set_ylabel("voltage") #y軸の名前 ax1.xaxis.set_major_locator(ticker.FixedLocator(position)) #軸の主要値の場所を指定 ax1.xaxis.set_major_formatter(ticker.FixedFormatter(labels)) #軸の主要値の名前を指定 ax2.set_title("cos wave") #図のタイトル ax2.set_xlabel("phase") #x軸の名前 ax2.set_ylabel("voltage") #y軸の名前 ax2.xaxis.set_major_locator(ticker.FixedLocator(position)) #軸の主要値の場所を指定 ax2.xaxis.set_major_formatter(ticker.FixedFormatter(labels)) #軸の主要値の名前を指定 plt.tight_layout() #グラフのラベルやタイトルが重ならないようにする plt.show
以上だよw