将dopri5与odeint boost库一起使用
Using dopri5 with odeint boost library
方程组
嗨。我想在时间上把这些方程从0发展到10^16,初始条件x(0)=10^8和y(0)=0.5。由于方程对分母中x的依赖性,我认为使用带runge_kutta_dopri5的odeint是一个很好的选择,因为它具有自适应阶跃控制。问题是,我不知道如何在实践中做到这一点,因为我在c++和odeint方面几乎没有经验。我搜索了很多关于使用odeint的信息,但这些例子对我没有帮助。此外,我想在x达到零时停止计算,我看到了这个https://stackoverflow.com/questions/33334073/stop-integration-in-odeint-with-stiff-ode
根据例子,我写这篇文章到目前为止没有运气
#include <iostream>
#include <vector>
#include <cmath>
#include <boost/array.hpp>
#include <boost/numeric/odeint.hpp>
using namespace std;
using namespace boost::numeric::odeint;
const double b = 43.0e17;
typedef boost::array< double , 2 > state_type;
void binary(const state_type &x , state_type &dxdt , double t )
{
dxdt[0] = -b*(64.0/5)*(1 + (73.0/24)*pow(x[1],2)
+ 37.0/96)*pow(x[1],4) )/pow(x[0],3)*pow(1-pow(x[1],2),7.0/2);
dxdt[1] = -b*(304.0/96)*x[1]*(1 + (121.0/304)*pow(x[1],2))
/pow(x[0],4)*pow((1 - pow(x[1],2)),5.0/2);
}
void write_binary( const state_type &x , const double t )
{
cout << t << 't' << x[0] << 't' << x[1] << 't' << x[2] << endl;
}
//I dont know what this does but the examples used it
struct streaming_observer
{
std::ostream& m_out;
streaming_observer( std::ostream &out ) : m_out( out ) { }
template< class State , class Time >
void operator()( const State &x , Time t ) const
{
m_out << t;
for( size_t i=0 ; i<x.size() ; ++i ) m_out << "t" << x[i] ;
m_out << "n";
}
};
//This was a first try with a given stepper but i want to replace it
int main(int argc, char **argv)
{
state_type x = { 20.871e8 , 0.5 }; // initial conditions
integrate( binary , x , 0.0 , 1000.0 , 0.1 , write_binary );
}
当我编译它运行时,我得到了这个错误
内部程序错误-断言(i<N)在常量T&boost::array::operator[]/usr/include/boost/array.hpp(129):超出范围中止(堆芯转储)
我怎样才能得到这份工作?
write_binary
函数写入数组边界并导致断言。x[2]
无效。
相关文章:
- 将 boost::odeint 与向量类一起使用,而无需调整向量的大小
- 如何将boost::asio::d eadline_timer 与Qt一起使用?
- 如何将来自 Boost.Python 的map_indexing_suite与自定义而不是标准对象一起使用?
- boost::interprocess::file_lock 与 std::ostream 一起使用时的错误行为
- 将boost::filtering_streambuf与newline_filter一起使用时为空文件
- 如何将前向声明与 boost::msm 一起使用以避免循环依赖?
- 将Bazel与本地Boost安装一起使用
- 将 boost::function 与指向派生类的共享指针的参数一起使用
- 在Windows 10和Visual Studio Community 2019下,将Boost与Bazel一起使用
- 将 boost-di 与配置文件和共享库一起使用
- Boost Asio和Co_await-与任何第三方回调一起使用
- 可以将boost :: unordered_map与std :: shared_ptr一起使用
- 将 boost odeint 与 std::map 和自定义向量空间代数一起使用时,没有可行的重载'='
- 无法让 matplotlib 事件处理程序与 Boost.Python 一起工作
- 将 boost::object_pool 与矢量一起使用时指针无效
- 如何与CMAKE一起使用VS 2017编译的Boost Filesystem库
- 如何将 boost::atomic_store 与 shared_ptr<T> 和 shared_ptr<const T> 一起使用?
- 与Boost一起使用溪流
- boost::与boost:asio绑定在一起.boost::绑定后续
- boost::与boost:asio绑定在一起.boost::绑定不起作用,从示例中复制