草庐IT

c++ - odeint的runge_kutta4与Matlab的ode45的比较

我想在odeintC++library中使用runge_kutta4方法.我已经在Matlab中解决了这个问题。我在Matlab中使用以下代码求解x''=-x-g*x',初始值x1=1,x2=0,如下main.mclearallclct=0:0.1:10;x0=[1;0];[t,x]=ode45('ODESolver',t,x0);plot(t,x(:,1));title('Position');xlabel('time(sec)');ylabel('x(t)');ODESolver.mfunctiondx=ODESolver(t,x)dx=zeros(2,1);g=0.15;dx(1

c++ - 来自 C++ 中拉格朗日/变分法的 ODE 求解器

我有一个一般性问题,我将在更具体的情况下提出这个问题。如果想找到双摆的动力学,可以从数学上推导出运动方程,重写ODE使其具有对数值计算有用的特殊形式,并使用C++中的odeint求解ODE(参见堆栈溢出的例子https://stackoverflow.com/a/30582741)。现在假设我们想对n个耦合摆(n在运行时已知)做同样的事情。这需要我们写一个所谓的拉格朗日函数(动能-势能),这个函数的不同导数将是我们需要求解的ODE。此外,必须以适合odeint的形式重写这些ODE。这对于一般人来说很难用手完成。在像Mathematica和Maple这样的程序中,这实际上很容易。可以从拉

c++ - 无法让 BOOST odeint 与 Adams-Bashforth-Moulton 一起工作

我在使用BOOSTodeint库中的Adams-Bashforth-Moulton方法时遇到了一些问题。我在Bulirsch-Stoer上取得了成功,但出于某种原因,每当我尝试使用大于2的阶数时,Adams-Bashforth-Moulton只会返回nan。如果我使用阶数1或2,我会得到双倍的真实答案。我已将代码缩减为:#include#include#include#includetypedefboost::arraystate_type;usingnamespaceboost::numeric::odeint;classBoost_odeint_rhs{public:Boost_o

python - 使用 scipy.integrate.odeint 求解 odes 系统(不断变化!)?

我目前有一个具有随时间变化的常量的颂歌系统。例如deffun(u,t,a,b,c):x=u[0]y=u[1]z=u[2]dx_dt=a*x+y*zdy_dt=b*(y-z)dz_dt=-x*y+c*y-zreturn[dx_dt,dy_dt,dz_dt]常数是“a”、“b”和“c”。我目前有每个时间步的“a”列表,我想在每个时间步插入,当使用scipyode求解器时......这可能吗?谢谢! 最佳答案 是的,这是可能的。如果a是常量,我猜你调用了scipy.integrate.odeint(fun,u0,t,args)其中fun是

python - scipy.integrate.odeint 和 scipy.integrate.ode 有什么区别?

我已经阅读了这些here的文档,但它只是声明odeint是“具有基于ODEPACK的lsoda的更简单接口(interface)的集成器”实际区别是什么?在什么情况下使用一种比另一种更合适? 最佳答案 如果您可以使用odeint解决您的问题,我会推荐它。它只是一个使用lsoda集成ode的函数。如果你想要更多的选择,ode是一个有很多方法和求解器的类:scipy.integrate.odescipy.integrate.ode.integratescipy.integrate.ode.set_f_paramsscipy.integr

python - scipy.integrate.odeint 和 scipy.integrate.ode 有什么区别?

我已经阅读了这些here的文档,但它只是声明odeint是“具有基于ODEPACK的lsoda的更简单接口(interface)的集成器”实际区别是什么?在什么情况下使用一种比另一种更合适? 最佳答案 如果您可以使用odeint解决您的问题,我会推荐它。它只是一个使用lsoda集成ode的函数。如果你想要更多的选择,ode是一个有很多方法和求解器的类:scipy.integrate.odescipy.integrate.ode.integratescipy.integrate.ode.set_f_paramsscipy.integr

python - 比较 Boost.Odeint 与 Scipy.integrate.odeint?

我最近偶然发现了boost.odeint库,我对可能性和可配置性的数量感到惊讶。但是,在广泛使用scipy.integrate.odeint(它本质上是Fortran中ODEPACK的包装器)之后,我想知道它们的性能如何比较。我知道boost.odeint还带有并行化,这对于scipy(据我所知)是不可能的,这会大大boost性能,但我要求的是单核案例。但是,由于在那种情况下我必须将boost.odeint(使用cython或boost.python)包装到python中,也许你们中有人已经这样做了?这将是一个伟大的成就,因为所有的分析可能性在Python中都更加先进。

c++ - 将 openmp 与 odeint 和自适应步长一起使用

我正在尝试使用openmp来并行化我的代码。当我使用恒定步长时一切正常,但是当我使用自适应步进器运行相同的代码时,我会收到我不理解的错误。以下是代码的基本部分:usingnamespacestd;usingnamespaceboost::numeric::odeint;constintjmax=10;typedefdoublevalue_type;typedefboost::arraystate_type;//Thestepfunctionvoidrhs(conststate_typeA,state_type&dAdt,constvalue_typet){value_typeRHSte

c++ - 如何将 vector 传递给基于推力的 odeint 观察器的构造函数,以便可以在仿函数中读取它

我正在扩展与thrust一起使用的boost的odeint的参数研究示例,我不知道如何将值vector传递给观察者的构造函数,以便可以从内部访问(只读)这些值观察者的仿函数。以下是仅供观察者使用的代码。////Observesthesystem,comparingthecurrentstateto////valuesinunchangingVectorstructminimum_perturbation_observer{structminPerturbFunctor{template__host____device__voidoperator()(Tt)const{////Iwoul

c++ - 使用 Boost::odeint 和 Eigen::Matrix 作为状态 vector

我正在尝试使用ODEintegrationcapabilitiesofBoost使用MatrixclassfromEigen3作为我的状态vector,但我在Boost中遇到了我不知道如何解决的问题。我正在尝试做的一个最小示例:#include#include#includeusingnamespaceEigen;usingnamespaceboost::numeric::odeint;templateusingvector=Matrix;typedefvectorstate;intmain(){stateX0;X0stepper;//IfIremovetheselines,every