パッケージを使用しdde23
てpydelay
遅延微分方程式を解いています。私の質問:条件付きで方程式をコーディングする方法は? たとえば、ターゲット方程式には 2 つのオプションがあります。
when x>1, dx/dt=0.25 * x(t-tau) / (1.0 + pow(x(t-tau),10.0)) -0.1*x
otherwise, dx/dt=0.25 * x
2 つの方法を試しましたが、どちらもうまくいかなかったようです。
アプローチ 1 は文句を言いませんでしたが、if else ステートメントが解釈されていません。
アプローチ 2 では、次のエラーが生成されました。
実行可能ファイルが見つかりました c:\mingw\bin\g++.exe c:\docume~1\thao\locals~1\temp\thong\python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ec4d311.cpp: 関数内 'double f(double, double)': c:\ docume~1\thao\locals~1\temp\thong\python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ec4d311.cpp:734: エラー: 'x' は関数として使用できません c:\docume~1\thao\locals~1\temp\thong\ python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ec4d311.cpp:734: エラー: 'x' は関数として使用できません c:\docume~1\thao\locals~1\temp\thong\python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ec4d311. *, PyObject*)': c:\docume~1\thao\locals~1\temp\thong\python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ec4d311.cpp:878: 警告: 符号付き整数式と符号なし整数式の比較 c:\docume~1\thao\locals~1\temp\thong\python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ec4d311.cpp:883: 警告: 符号付き整数式と符号なし整数式の比較 c:\docume~1\thao\locals~1\temp\thong\python27_compiled \sc_f68f7a878bf7b27c6f72c9e771ec4d311.cpp:774: 警告: 未使用の変数 'Nhistx_ar' c:\docume~1\thao\locals~1\temp\thong\python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ec4d311.cpp:775: 未使用の cppx 変数: cpp:775 ~1\thao\locals~1\temp\thong\python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ec4d311.cpp:776: 警告: 未使用の変数 'Dhistx_ar' c:\docume~1\thao\locals~1\temp\thong\python27_compiled\sc_f68f7a878bf7b27cppe3f17. :785: 警告: 未使用の変数 'NVhistx_ar' c:\docume~1\thao\locals~1\temp\thong\python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ec4d311.cpp:786:警告: 未使用の変数 'SVhistx_ar' c:\docume~1\thao\locals~1\temp\thong\python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ec4d311.cpp:787: 警告: 未使用の変数 'DVhistx_ar' c:\docume~1\thao\locals~ 1\temp\thong\python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ec4d311.cpp:796: 警告: 未使用の変数 'NThist_ar' c:\docume~1\thao\locals~1\temp\thong\python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ecd:1 未使用 c971ecd1 'SThist_ar' c:\docume~1\thao\locals~1\temp\thong\python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ec4d311.cpp:798: 警告: 未使用の変数 'DThist_ar' c:\docume~1\thao\locals~1\temp\ thong\python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ec4d311.cpp:817: 警告: 未使用の変数 'Ndiscont' c:\docume~1\thao\locals~1\temp\thong\python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ec4d311.cpp:818: 警告: 未使用の変数「Sdiscont」 .cpp:819: 警告: 未使用の変数 'Ddiscont' トレースバック (最新の呼び出しが最後): ファイル "C:\Documents and Settings\thao\Desktop\mackey-glass.py"、33 行目、dde.run() ファイル"C:\Python27\lib\site-packages\pydelay_dde23.py", 行 1120, in run compiler = 'gcc') ファイル "C:\Python27\lib\site-packages\scipy\weave\inline_tools.py",行 355、インライン **kw) ファイル "C:\Python27\lib\site-packages\scipy\weave\inline_tools.py"、行 482、compile_function verbose=verbose、**kw) ファイル "C:\Python27 \lib\site-packages\scipy\weave\ext_tools.py",367 行目、コンパイル verbose = verbose、**kw) ファイル "C:\Python27\lib\site-packages\scipy\weave\build_tools.py"、272 行目、build_extension setup(name = module_name, ext_modules = [ext ],verbose=verb) File "C:\Python27\lib\site-packages\numpy\distutils\core.py", line 186, in setup return old_setup(**new_attr) File "C:\Python27\lib\distutils \core.py", line 169, in setup raise SystemExit, "error: " + str(msg) distutils.errors.CompileError: error: Command "g++ -O2 -Wall -IC:\Python27\lib\site-packages\ scipy\weave -IC:\Python27\lib\site-packages\scipy\weave\scxx -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\include -IC:\Python27\ PC -cc:\docume~1\thao\locals~1\temp\thong\python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ec4d311.cpp -oc:\docume~1\thao\locals~1\temp\thong\python27_intermediate\compiler_a77d1132635f0379270bcb96a5e542fc\Release\docume~1\thao\locals~1\temp\thong\python27_compiled\sc_f68f7a878bf7b27c6f72c9e771ec4d311.o で終了ステータス [Finished in exit in 1.o.終了コード 1 の s]
アプローチ 1 (if else ステートメントを使用して、eqns
どれが python dict であるかを更新します):
import numpy as np
import pylab as pl
from pydelay import dde23
eqn_1a='0.25 * x(t-tau) / (1.0 + pow(x(t-tau),10.0)) -0.1*x'
eqn_1b='0.45 * x'
eqns = { 'x' : eqn_1a if 'x>1' else eqn_1b}
dde = dde23(eqns=eqns, params={'tau': 15})
dde.set_sim_params(tfinal=1000, dtmax=1.0, AbsTol=10**-6, RelTol=10**-3)
histfunc = {'x': lambda t: 0.5 }
dde.hist_from_funcs(histfunc, 51)
dde.run()
sol1 = dde.sample(2, 3, 0.1)
x1 = sol1['x']
アプローチ 2 (C コードをソルバーに提供する):
eqns = { 'x' : 'f(x, tau)'}
# We can define a c function to be used in the equations
mycode = """
double f(double x, double tau) {
if (x>1){
return (0.25 * x(t-tau) / (1.0 + pow(x(t-tau),10.0)) -0.1*x);
}
else{
return (0.45 * x);
}
}
"""
dde = dde23(eqns=eqns, params={'tau': 15}, supportcode=mycode)
dde.set_sim_params(tfinal=1000, dtmax=1.0, AbsTol=10**-6, RelTol=10**-3)
histfunc = {'x': lambda t: 0.5 }
dde.hist_from_funcs(histfunc, 51)
dde.run()
sol1 = dde.sample(1, 300, 1)
x1 = sol1['x']