簡単な質問で申し訳ありませんが、odeint の状態変数の進化をダウンサンプリングするための「ベスト プラクティス」はありますか?
以下に、この記事 ( http://www.codeproject.com/Articles/268589/odeint-v2-Solving-ordinary-differential-equations )
struct streaming_observer
{
std::ostream &m_out;
streaming_observer( std::ostream &out ) : m_out( out ) {}
void operator()( const state_type &x , double t ) const
{
m_out << t;
for( size_t i=0 ; i < x.size() ; ++i )
m_out << "\t" << x[i];
m_out << "\n";
}
};
// ...
integrate_const( runge_kutta4< state_type >() , lorenz , x , 0.0 , 10.0 , dt , streaming_observer( std::cout ) );
オブザーバーをどのように変更して、10 ステップごとに状態のみをログに記録しますか (たとえば)。ifステートメントを入れるよりもエレガントな解決策があるかどうか疑問に思っています:
struct streaming_observer
{
std::ostream &m_out;
int count;
streaming_observer( std::ostream &out ) : m_out( out ) {count = 10;}
void operator()( const state_type &x , double t ) const
{
if( count == 10 ) {
count = 1;
m_out << t;
for( size_t i=0 ; i < x.size() ; ++i )
m_out << "\t" << x[i];
m_out << "\n";
}
else {
count++;
}
}
};