Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58982 - sandbox/odeint/libs/numeric/odeint/examples
From: mario.mulansky_at_[hidden]
Date: 2010-01-13 12:26:45


Author: mariomulansky
Date: 2010-01-13 12:26:45 EST (Wed, 13 Jan 2010)
New Revision: 58982
URL: http://svn.boost.org/trac/boost/changeset/58982

Log:
+doc example
Added:
   sandbox/odeint/libs/numeric/odeint/examples/doc_harm_osc.cpp (contents, props changed)

Added: sandbox/odeint/libs/numeric/odeint/examples/doc_harm_osc.cpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/libs/numeric/odeint/examples/doc_harm_osc.cpp 2010-01-13 12:26:45 EST (Wed, 13 Jan 2010)
@@ -0,0 +1,45 @@
+#include <iostream>
+
+#include <boost/numeric/odeint.hpp>
+
+//[ rhs_function
+/* The type of container used to hold the state vector */
+typedef std::vector<double> state_type;
+
+const double gam = 0.15;
+
+/* The rhs of x' = f(x) */
+void harmonic_oscillator(const state_type &x, state_type &dxdt, const double t)
+{
+ dxdt[0] = x[1];
+ dxdt[1] = -x[0] - gam*x[1];
+}
+//]
+
+int main(int argc, char **argv)
+{
+ using namespace std;
+ using namespace boost::numeric::odeint;
+
+ //[ state_initialization
+ state_type x(2);
+ x[0] = 1.0; // start at x=1.0, p=0.0
+ x[1] = 0.0;
+ //]
+
+ //[ integration
+ vector<double> times;
+ vector<state_type> x_t_vec;
+
+ size_t steps = integrate( harmonic_oscillator ,
+ x , 0.0 , 10.0 ,
+ back_inserter( times ) ,
+ back_inserter( x_t_vec ) );
+ //]
+
+ //[ output
+ for( size_t i=0; i<=steps; i++ ) { //initial state is 0th entry
+ cout << times[i] << '\t' << x_t_vec[i][0] << '\t' << x_t_vec[i][1] << '\n';
+ }
+ //]
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk