pythonで数値計算のプログラムを書いているのですが、
terminal
1Traceback (most recent call last): 2 File "task.py", line 35, in <module> 3 x_2d, x1, x2 = fd(t, x_2d) 4 File "task.py", line 14, in fd 5 A_2d = np.array([[x2_now], [u(t)]])
という風にエラーが出てしまうのですが、どこを変更すればよいのでしょうか。
python
1#coding utf-8 2import math 3import numpy as np 4import matplotlib.pyplot as plt 5 6def u(t): 7 P = np.pi 8 u_cul = (1.0/0.159103) * math.sin(2.0*P*t) 9 return u_cul 10 11def fd(t, x_2d): 12 x2_now = x_2d[1][0] 13 A_2d = 0.0 14 A_2d = np.array([[x2_now], [u(t)]]) 15 16 dx1_2d = DT * A_2d / 6.0 17 dx2_2d = DT * A_2d / 3.0 18 dx3_2d = DT * A_2d / 3.0 19 dx4_2d = DT * A_2d / 6.0 20 dx_2d_sum = dx1_2d + dx2_2d + dx3_2d + dx4_2d 21 x_2d = x_2d + dx_2d_sum 22 return x_2d, x_2d[0][0], x_2d[1][0] 23 24 25DT = 0.01 26t = 0.0 27x_2d = np.array([[0.0], [0.0]]) 28t_list = [] 29x1_list = [] 30x2_list = [] 31u_list = [] 32 33for i in range(0,101): 34 t_list.append(t) 35 x_2d, x1, x2 = fd(t, x_2d) 36 u = u(t) 37 x1_list.append(x1) 38 x2_list.append(x2) 39 u_list.append(u) 40 t = t + DT 41 42 43plt.plot(t_list, u_list, c='green', label='u') 44plt.plot(t_list, x1_list, c='blue', label='x1') 45plt.plot(t_list, x2_list, c='red', label='x2') 46 47plt.title('', fontsize = 20) 48plt.xlabel('t', fontsize = 16) 49plt.ylabel('x', fontsize = 16) 50plt.tick_params(labelsize=14) 51plt.grid(True) 52plt.legend() 53plt.show()
pythonを始めたばかりでコードが読みにくいと思いますが、
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/02 01:11
2019/06/02 01:18