我想求解相同的ODE,但要使用几个不同的初始条件。我可以用一个固定的初始条件求解,例如,在示例中,我选择x [0] = x [1] = x [2] = 10.0。如何创建一个while循环来求解x [0] = 10.0,9.0,.... 1.0的ODE?这是代码:
#include <vector>
#include<boost/numeric/odeint.hpp>
typedef std::vector<double> state_type;
const double sigma = 10.0;
const double R = 28.0;
const double b = 8. / 3.;
void lorenz(state_type &x, state_type &dxdt, double t)
{
dxdt[0] = sigma * (x[1] - x[0]);
dxdt[1] = R * x[0] - x[0] - x[0] * x[2];
dxdt[2] = x[0] * x[1] - b * x[3];
}
int main()
{
using namespace std;
using namespace boost::numeric::odeint;
state_type x(3);
x[0] = x[1] = x[2] = 10.0;
const double dt = 0.01;
auto stepper = make_dense_output<runge_kutta_dopri5<state_type> >(1.0E-12,
1.0E-12);
double t = 0.0;
stepper.initialize(x, t, dt);
cout << t << " " << x[0] << endl;
t = t + dt;
while (t < 10)
{
if (t > stepper.current_time())
{
stepper.do_step(lorenz);
}
else
{
stepper.calc_state(t, x);
cout << t << " " << x[0] << endl;
t += dt;
}
}
return 0;
}
除此之外,还有谁能给我展示一个最低限度的示例或文档,让我可以阅读有关并行化此类ODE问题的信息?对于给您带来的任何不便,我深表歉意。我正在开始使用C ++。