前提・実現したいこと
python,scipyのodeint使って非線形微分方程式の数値解析をしようと考えています.
発生している問題・エラーメッセージ
非線形部分(プログラム中vector_solove関数内のnextx2の右辺側- μ(x2)gnp.sign(x2))を入れると下記の警告が出ます.
PS C:\Users\N\Desktop\○○\□> python sample-erro-odeint.py C:\Users\N\AppData\Local\Programs\Python\Python37\lib\site-packages\scipy\integrate\odepack.py:247: ODEintWarning: Excess work done on this call (perhaps wrong Dfun type). Run with full_output = 1 to get quantitative information. warnings.warn(warning_msg, ODEintWarning)
該当のソースコード
python
1import matplotlib 2#matplotlib.use('Agg') 3import matplotlib.pyplot as plt 4from scipy.integrate import odeint 5from scipy.integrate import solve_ivp 6import numpy as np 7import pylab 8from openpyxl import Workbook 9 10ms = 0.26 11mc = 0.85 12k = 177 13g = 9.8 14 15m = mc + (1/3)*ms 16 17def μ(x2): 18 if x2==0: 19 return 0.24 20 else: 21 return 0.11 22 23def d(t): 24 25 if t < 20: 26 return 0 27 elif t >= 20: 28 return 5*np.sin(3.14*t) 29 30def vector_solove(state,t): 31 32 x1, x2, x3 = state 33 34 nextx3 = x1 - 0.02*np.sin(t) 35 nextx1 = x2 36 nextx2 = -(k/m)*x1 - (k/m)*((7*(x1-0.02*np.sin(t)))+(0.1*(x2-0.02*np.cos(t))) + 30*x3) + d(t) - μ(x2)*g*np.sign(x2) 37 38 return nextx1, nextx2, nextx3 39 40x1_f = 0 41x2_f = 0 42x3_f = 0 43#t_span = [0, 40] 44t = np.arange(0.0, 40.0, 0.01) 45v = odeint(vector_solove, [x1_f, x2_f,x3_f], t) 46x1_vec = v[:,0] 47x2_vec = v[:,1] 48 49#以下,グラフ表示部分 50fig, ax = plt.subplots(2, 1, figsize=(10,6)) 51 52 53ax[0].set_xlabel('Time[s]') 54ax[0].set_ylabel('Position[m]') 55ax[0].grid() 56ax[0].set_ylim(-0.03, 0.08) 57ax[0].set_xlim(0.0, 40.0) 58ax[0].plot(t, x1_vec, ls = '-', label = 'PID Controler') 59ax[0].legend() 60 61ax[1].set_xlabel('Time[s]') 62ax[1].set_ylabel('Velocity[m/s]') 63ax[1].grid() 64ax[1].set_ylim(-0.1, 0.2) 65ax[1].set_xlim(0.0, 40.0) 66ax[1].plot(t, x2_vec, ls = '-', label = 'PID Controler') 67ax[1].legend() 68plt.show()
試したこと
警告の中身に(perhaps wrong Dfun type)と出ているので,odeintの公式のホームページ?で調べたら下記のものが出てきましたが,意味が分かりませんでした.
Dfun:callable(y, t, …) or callable(t, y, …) Gradient (Jacobian) of func. If the signature is callable(t, y, ...), then the argument tfirst must be set True.
また警告内容でRun with full_output = 1 to get quantitative information. とあるので同様に調べてみると,
full_output:bool, optional True if to return a dictionary of optional outputs as the second output
と書いてありましたがわかりませんでした
補足情報(FW/ツールのバージョンなど)
特にscipyのodeintにこだわっているわけではないので,odeやsolve_ivpのほうが使いやすいのであればそちらの方を教えてください.
あなたの回答
tips
プレビュー