Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57075 - sandbox/odeint/libs/numeric/odeint/examples
From: karsten.ahnert_at_[hidden]
Date: 2009-10-22 14:43:40


Author: karsten
Date: 2009-10-22 14:43:39 EDT (Thu, 22 Oct 2009)
New Revision: 57075
URL: http://svn.boost.org/trac/boost/changeset/57075

Log:
added lorenz array example
Added:
   sandbox/odeint/libs/numeric/odeint/examples/lorenz_array.cpp (contents, props changed)

Added: sandbox/odeint/libs/numeric/odeint/examples/lorenz_array.cpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/libs/numeric/odeint/examples/lorenz_array.cpp 2009-10-22 14:43:39 EDT (Thu, 22 Oct 2009)
@@ -0,0 +1,72 @@
+/* Boost numeric/odeint/examples/lorenz_array.cpp
+
+ Copyright 2009 Karsten Ahnert
+
+ Shows, the usage of odeint, and integrates the Lorenz equations,
+ a deterministic chaotic system
+
+ dx/dt = sigma * ( x - y)
+ dy/dt = R*x - y - x*z
+ dz/dt = x*y - b*z
+
+ mit sigma = 10, r=28, b = 8/3
+
+ Distributed under the Boost Software License, Version 1.0.
+(See accompanying file LICENSE_1_0.txt or
+ copy at http://www.boost.org/LICENSE_1_0.txt)
+*/
+
+#include <iostream>
+#include <vector>
+#include <list>
+#include <tr1/array>
+
+#include <boost/numeric/odeint.hpp>
+
+#define tab "\t"
+
+using namespace std;
+using namespace std::tr1;
+using namespace boost::numeric::odeint;
+
+const double sigma = 10.0;
+const double R = 28.0;
+const double b = 8.0 / 3.0;
+
+const double dt = 0.01;
+const size_t olen = 10000;
+
+typedef array<double, 3> state_type;
+
+void lorenz( state_type &x , state_type &dxdt , double t )
+{
+ dxdt[0] = sigma * ( x[1] - x[0] );
+ dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
+ dxdt[2] = x[0]*x[1] - b * x[2];
+}
+
+int main( int argc , char **argv )
+{
+ state_type x;
+ x[0] = 1.0;
+ x[1] = 0.0;
+ x[2] = 0.0;
+
+ ode_step_euler< state_type , array_resizer<double,3> > euler;
+
+ double t = 0.0;
+ for( size_t oi=0 ; oi<olen ; ++oi,t+=dt )
+ {
+ cout << t << tab << x[0] << tab << x[1] << tab << x[2] << endl;
+ euler.next_step( lorenz , x , t , dt );
+ }
+
+ return 0;
+}
+
+
+
+/*
+ Compile with
+ g++ -Wall -I$BOOST_ROOT -I../../../../ lorenz_array.cpp
+*/


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