Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8743719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:43:35+00:00 2026-06-13T11:43:35+00:00

Could anyone provide me with some assistance in creating a minimum example of using

  • 0

Could anyone provide me with some assistance in creating a minimum example of using the c++ odeint solver with a vector of complex numbers and if possible with higher precision (boost.multiprecision or libquadmath __float128 , __complex128 say).

There is an example in the docs using a complex scalar http://headmyshoulder.github.com/odeint-v2/doc/boost_numeric_odeint/tutorial/special_topics.html

and it’s mentioned there that :

The fact that we have to configure a different algebra is solely due to the fact 
that we use a non-vector state type and not to the usage of complex values.
So for, e.g. vector<  complex<double> >, this would not be required. 

I tried to modify this with changes like typedef vector<complex<double>> state_type:

#include <iostream>
#include <complex>
#include <boost/array.hpp>

#include <boost/numeric/odeint.hpp>

using namespace std;
using namespace boost::numeric::odeint;


typedef vector<complex< double >> state_type;

struct stuart_landau
{
double m_eta;
double m_alpha;

stuart_landau( double eta = 1.0 , double alpha = 1.0 )
: m_eta( eta ) , m_alpha( alpha ) { }

void operator()( const state_type &x , state_type &dxdt , double t ) const
{
    const complex<double> I(0.0,1.0);
    dxdt[0] = x[1];
    dxdt[1] = (1.0+m_eta*I)*x[0]-(1.0+m_alpha*I)*x[1];
}
};

 struct streaming_observer
{
std::ostream& m_out;

streaming_observer( std::ostream &out ) : m_out( out ) { }

template< class State >
void operator()( const State &x , double t ) const
{
    m_out << t;
    m_out << "\t" << x[0].real() << "\t" << x[0].imag() ;
    m_out << "\n";*/
}
};

int main( int argc , char **argv )
{
//[ stuart_landau_integration
state_type x(2);
 x[0] = complex< double >( 1.0 , 0.0 );
 x[1] = complex< double >( 1.0 , 0.0 );

const double dt = 0.1;

typedef runge_kutta4< state_type , double , state_type , double ,
                      vector_space_algebra > stepper_type;

integrate_const( stepper_type() , stuart_landau( 2.0 , 1.0 ) , x , 0.0 , 10.0 , dt , streaming_observer( cout ) );
//]

return 0;

}

However this gives a plethora of errors.

Could anyone give me a minimum working example with complex ODEs? and even better implementing high precision data types..It looks like odeint can support quite arbitrary state types but I’m having a lot of trouble getting them to work.

Updated code

#include <iostream>
#include <complex>
#include <boost/array.hpp>
#include <stdlib.h>
#include <math.h>

#include <boost/numeric/odeint.hpp>


extern "C" {
#include <quadmath.h>
}

using namespace std;
using namespace boost::numeric::odeint;

//[ stuart_landau_system_function
typedef std::vector<std::complex < __float128 > > state_type;

struct stuart_landau
{
__float128 m_eta;
__float128 m_alpha;

stuart_landau( __float128 eta = 1.0L , __float128 alpha = 1.0L )
: m_eta( eta ) , m_alpha( alpha ) { }

void operator()( const state_type &x , state_type &dxdt , double t ) const
{
    const complex< __float128 > I( 0.0 , 1.0 ); //define complex I     

    dxdt[0] = x[1];
    dxdt[1] = ( 1.0 + m_eta * I ) * x[0] - ( 1.0 + m_alpha * I )*x[1];
}
};
//]




struct streaming_observer
{
 std::ostream& m_out;

streaming_observer( std::ostream &out ) : m_out( out ) { }

template < class State >
void operator()( const State &x , double t ) const
{
    m_out << t;
  /*  m_out << "\t" << x[0].real() << "\t" << x[0].imag() ;
    m_out << "\n";*/
 }
};




int main( int argc , char **argv )
{
//[ stuart_landau_integration
state_type x(2);
 x[0] = complex< __float128 >( 1.0L , 0.0L );
 x[1] = complex< __float128 >( 1.0L , 0.0L );

const double dt = 0.1;

typedef runge_kutta4< state_type, __float128 > stepper_type;

integrate_const( stepper_type() , stuart_landau( 2.0L , 1.0L ) , x , 0.0 , 10.0 , dt    
 /*, streaming_observer( cout ) */);
 //]

 return 0;
 }

ERROR LOG ON COMPILE:

vecPrec.cpp: In member function ‘void stuart_landau::operator()(const state_type&,    
state_type&, double) const’:
 vecPrec.cpp:33:35: error: no match for ‘operator+’ in ‘1.0e+0 + std::operator* [with 
 _Tp = __float128]((* &((const stuart_landau*)this)->stuart_landau::m_eta), (* & I))’
 vecPrec.cpp:33:35: note: candidates are:
 /usr/include/c++/4.6/bits/stl_iterator.h:327:5: note: template<class _Iterator>    std::reverse_iterator<_Iterator> std::operator+(typename 

 std::reverse_iterator<_Iterator>::difference_type, const   std::reverse_iterator<_Iterator>&)
 /usr/include/c++/4.6/bits/basic_string.h:2306:5: note: template<class _CharT, class  _Traits, class _Alloc> std::basic_string<_CharT, _Traits, _Alloc> std::operator+(const    std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits,   _Alloc>&)
 /usr/include/c++/4.6/bits/basic_string.tcc:694:5: note: template<class _CharT, class  _Traits, class _Alloc> std::basic_string<_CharT, _Traits, _Alloc> std::operator+(const   _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
  /usr/include/c++/4.6/bits/basic_string.tcc:710:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_string<_CharT, _Traits, _Alloc> std::operator+(_CharT,     const std::basic_string<_CharT, _Traits, _Alloc>&)
  /usr/include/c++/4.6/bits/basic_string.h:2343:5: note: template<class _CharT, class  _Traits, class _Alloc> std::basic_string<_CharT, _Traits, _Alloc> std::operator+(const   std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
 /usr/include/c++/4.6/bits/basic_string.h:2359:5: note: template<class _CharT, class   _Traits, class _Alloc> std::basic_string<_CharT, _Traits, _Alloc> std::operator+(const   std::basic_string<_CharT, _Traits, _Alloc>&, _CharT)
  /usr/include/c++/4.6/complex:321:5: note: template<class _Tp> std::complex<_Tp>  std::operator+(const std::complex<_Tp>&, const std::complex<_Tp>&)
   /usr/include/c++/4.6/complex:330:5: note: template<class _Tp> std::complex<_Tp>  std::operator+(const std::complex<_Tp>&, const _Tp&)
    /usr/include/c++/4.6/complex:339:5: note: template<class _Tp> std::complex<_Tp>  std::operator+(const _Tp&, const std::complex<_Tp>&)
   /usr/include/c++/4.6/complex:440:5: note: template<class _Tp> std::complex<_Tp>  std::operator+(const std::complex<_Tp>&)
   /usr/include/c++/4.6/bits/stl_bvector.h:266:3: note: std::_Bit_iterator   std::operator+(std::ptrdiff_t, const std::_Bit_iterator&)
   /usr/include/c++/4.6/bits/stl_bvector.h:266:3: note:   no known conversion for argument 2 from ‘std::complex<__float128>’ to ‘const std::_Bit_iterator&’
    /usr/include/c++/4.6/bits/stl_bvector.h:352:3: note: std::_Bit_const_iterator std::operator+(std::ptrdiff_t, const std::_Bit_const_iterator&)
   /usr/include/c++/4.6/bits/stl_bvector.h:352:3: note:   no known conversion for   argument 2 from ‘std::complex<__float128>’ to ‘const std::_Bit_const_iterator&’
   vecPrec.cpp:33:66: error: no match for ‘operator+’ in ‘1.0e+0 + std::operator*  [with _Tp = __float128]((* &((const stuart_landau*)this)->stuart_landau::m_alpha), (* &   I))’
  vecPrec.cpp:33:66: note: candidates are:
   /usr/include/c++/4.6/bits/stl_iterator.h:327:5: note: template<class _Iterator>   std::reverse_iterator<_Iterator> std::operator+(typename    std::reverse_iterator<_Iterator>::difference_type, const std::reverse_iterator<_Iterator>&)
   /usr/include/c++/4.6/bits/basic_string.h:2306:5: note: template<class _CharT, class     _Traits, class _Alloc> std::basic_string<_CharT, _Traits, _Alloc> std::operator+   (const std::basic_string<_CharT, _Traits, _Alloc>&, const   std::basic_string<_CharT, _Traits, _Alloc>&)
  /usr/include/c++/4.6/bits/basic_string.tcc:694:5: note: template<class _CharT, class   _Traits, class _Alloc> std::basic_string<_CharT, _Traits, _Alloc> std::operator+  (const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
   /usr/include/c++/4.6/bits/basic_string.tcc:710:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_string<_CharT, _Traits, _Alloc> std::operator+   (_CharT, const std::basic_string<_CharT, _Traits, _Alloc>&)
    /usr/include/c++/4.6/bits/basic_string.h:2343:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
   /usr/include/c++/4.6/bits/basic_string.h:2359:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::basic_string<_CharT, _Traits, _Alloc>&, _CharT)
   /usr/include/c++/4.6/complex:321:5: note: template<class _Tp> std::complex<_Tp> std::operator+(const std::complex<_Tp>&, const std::complex<_Tp>&)
    /usr/include/c++/4.6/complex:330:5: note: template<class _Tp> std::complex<_Tp> std::operator+(const std::complex<_Tp>&, const _Tp&)
   /usr/include/c++/4.6/complex:339:5: note: template<class _Tp> std::complex<_Tp> std::operator+(const _Tp&, const std::complex<_Tp>&)
   /usr/include/c++/4.6/complex:440:5: note: template<class _Tp> std::complex<_Tp> std::operator+(const std::complex<_Tp>&)
   /usr/include/c++/4.6/bits/stl_bvector.h:266:3: note: std::_Bit_iterator std::operator+(std::ptrdiff_t, const std::_Bit_iterator&)
   /usr/include/c++/4.6/bits/stl_bvector.h:266:3: note:   no known conversion for argument 2 from ‘std::complex<__float128>’ to ‘const std::_Bit_iterator&’
   /usr/include/c++/4.6/bits/stl_bvector.h:352:3: note: std::_Bit_const_iterator std::operator+(std::ptrdiff_t, const std::_Bit_const_iterator&)
   /usr/include/c++/4.6/bits/stl_bvector.h:352:3: note:   no known conversion for argument 2 from ‘std::complex<__float128>’ to ‘const std::_Bit_const_iterator&’
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:43:36+00:00Added an answer on June 13, 2026 at 11:43 am

    In order to get the above example to work you need to use the range_algebra. You are using the vector_space_algebra which expects more or less that for the state_type all operators +*-/ are defined. This is not the case for std::vector<>. Simply use

    typedef runge_kutta4< state_type > stepper_type;
    

    This typedef silenty uses the range_algebra.

    For the other case try

    typedef vector< complex< __float128 > > state_type;
    typedef runge_kutta4< state_type , __float128 > stepper_type;
    

    The precondition for the above two lines to work is that for __float128 the operators-*/+ are already defined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could anyone provide working example in C++ with event handling for Skype4COM, i.e. incoming
I could really use an example of this. Can anyone provide me with a
Could anyone provide some guidance on how to implement that speech-bubble like popup menu
Can anyone provide an example of using HTTParty using digest auth? I can't find
ASP.NET: Could anyone provide some C# paging codes in Repeater or ListView controls for
Could anyone provide me with the pointers to source code for linux commands such
http://docs.oracle.com/javase/1.5.0/docs/guide/jpda/trace.html Could anyone please provide me couple of examples of how to use Java
Could anyone give me some help with this please? The content needs to appear
Hi I'm noticing some odd behavior while using SMO and was wondering if anyone
Could anyone guide me in created a simple app in JS? What the app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.