Reputation: 61
I downloaded odeint-v2 in a folder called C++. I created a new cpp file called HARMONIC.cpp.
#include <iostream>
#include <vector>
#include <boost/numeric/odeint.hpp>
using namespace boost::numeric::odeint;
std::vector<double> state_type;
double gam = 0.15;
void harmonic_oscillator( const state_type &x , state_type &dxdt , const double )
{
dxdt[0] = x[1];
dxdt[1] = -x[0] - gam*x[1];
}
int main(int, char**)
{
using namespace std;
using namespace boost::numeric::odeint;
state_type x(2);
x[0] = 1.0;
x[1] = 0.0;
size_t steps = integrate( harmonic_oscillator, x , 0.0 , 10.0 , 0.1 );
}
While compiling in ubuntu g++ HARMONIC.cpp -o har.output
The error is as following`
HARMONIC.cpp:4:36: fatal error: boost/numeric/odeint.hpp: No such file or directory compilation terminated.
But i downloaded in the same folder all the odeint-v2.
Please help me
Upvotes: 1
Views: 1430
Reputation: 368241
There are a number of different issues going on here.
You seem confused about what the library does and where you get it from. By far the easiest route is to install the Ubuntu boost packages via sudo apt-get install libboost-all-dev
.
The example you copied was missing a critical typedef
; else state_type
is not defined. This has been fixed.
I added a simple 'Done' statement at the end.
With that, it all just works.
Demo:
/tmp$ g++ -o boost_ode boost_ode.cpp
/tmp$ ./boost_ode
Done.
/tmp$
The repaired code is below.
/tmp$ cat boost_ode.cpp
#include <iostream>
#include <vector>
#include <boost/numeric/odeint.hpp>
using namespace boost::numeric::odeint;
typedef std::vector<double> state_type;
double gam = 0.15;
void harmonic_oscillator( const state_type &x , state_type &dxdt , const double )
{
dxdt[0] = x[1];
dxdt[1] = -x[0] - gam*x[1];
}
int main(int, char**)
{
using namespace std;
using namespace boost::numeric::odeint;
state_type x(2);
x[0] = 1.0;
x[1] = 0.0;
size_t steps = integrate( harmonic_oscillator, x , 0.0 , 10.0 , 0.1 );
std::cout << "Done." << std::endl;
}
/tmp$
Upvotes: 1