[英]Solution for differential equation is completly different in boost::odeint and scipy.integrate
I am trying to port my rapid prototyping from python to C++. 我正在尝试将快速原型从python移植到C ++。 I try to test the notation with a simple differential equation, but the results are very different for starting value [2,0].
我尝试使用一个简单的微分方程来测试表示法,但是对于起始值[2,0],结果却大不相同。 Python is declining, while the C++ solution is rising strongly.
Python正在下降,而C ++解决方案正在迅速上升。
It worked for a sample found here: How to incorporate time-varying parameters from lookup table into boost::odeint, c++ 它适用于以下示例: 如何将查找表中的时变参数合并到boost :: odeint,c ++
but it does not work for my example 但这对我的例子不起作用
TransferF::TransferF(const double& deltaT) : dt(deltaT), t(0.0), y(2)
{
// initial values
y[0] = 2.0; // x1
y[1] = 0.0; // x2
}
void TransferF::ode(const state_type &x, state_type &y, double t)
{
y[0] = x[0];
y[1] = x[1];
y[2] = (-2*y[1] - y[0] + 1) / (pow(y[0],2));
}
and the same in py: 和在py中相同:
def modelt(x,t):
y = x[0]
dydt = x[1]
dy2dt2 = (-2*dydt - y + 1)/ (y **2)
return [dydt,dy2dt2]
x3 = odeint(modelt,[2,0],timev)
I expected the same results for the time series, but pythons solution is falling, C++ is rising. 我希望时间序列的结果相同,但是pythons解决方案正在下降,C ++正在上升。
The C++ code has a subtle inconsistency. C ++代码存在细微的不一致。 The output vector
y
should only contain the derivatives y', y"
, not the function y
itself: 输出向量
y
应该只包含导数y', y"
,而不能包含函数y
本身:
void TransferF::ode(const state_type &x, state_type &y, double t)
{
y[0] = x[1];
y[1] = (-2*x[1] - x[0] + 1) / (pow(x[0],2));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.