Click here to Skip to main content
15,895,746 members
Articles / Programming Languages / CUDA

odeint v2 - Solving ordinary differential equations in C++

Rate me:
Please Sign up or sign in to vote.
4.64/5 (18 votes)
19 Oct 2011CPOL19 min read 130K   2.8K   34  
odeint v2 - Solving ordinary differential equations in C++
/*
*/

#include <cmath>

#include <boost/array.hpp>

template< size_t N >
struct phase_lattice
{
	typedef double value_type;
	typedef boost::array< value_type , N > state_type;

	value_type m_epsilon; 
	state_type m_omega;

	phase_lattice() : m_epsilon( 6.0/(N*N) ) // should be < 8/N^2 to see phase locking
	{
		for( size_t i=1 ; i<N-1 ; ++i )
			m_omega[i] = m_epsilon*(N-i);
	}

	void inline operator()( const state_type &x , state_type &dxdt , const double t ) const
	{
	    double c = 0.0;

		for( size_t i=0 ; i<N-1 ; ++i )
		{
		    dxdt[i] = m_omega[i] + c;
		    c = ( x[i+1] - x[i] );
		    dxdt[i] += c;
		}

		//dxdt[N-1] = m_omega[N-1] + sin( x[N-1] - x[N-2] );
	}

};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions