Em có chương trình sau sử dụng thư viện ODEINT trong boost. Nhưng không hiểu sao lúc cout kết quả (ví dụ như BW_test) từ hàm ode_write () thì giá trị đầu tiên lại bằng 0, nhưng nếu cout BW từ hàm khác: GarunsFlow() hoặc void ode_system( const state_type &x , state_type &dxdt , const double t ) thì giá trị đầu tiên khác 0 đúng như mong đợi. Em đã đọc lui đọc tới để xem trật tự hàm cũng như xem có cái nào chưa đc link không, mà ko tìm ra đc. Nhờ các anh chị trong nhóm xem giúp em với ạ.
Em cảm ơn nhiều!
#include <iostream>
#include <boost/array.hpp>
#include <boost/numeric/odeint.hpp>
using namespace std;
using namespace boost::numeric::odeint;
const double sigma = 0.0018;
enum DECLARE_ODE {A};
typedef boost::array< double, 1 > state_type;
struct GarunsFlow_c{
double sen;
double BW;
};
GarunsFlow_c GarunsFlow(const state_type &state)
{
GarunsFlow_c r;
r.sen =sigma * state[A] * (1-state[A]);
r.BW = state[A];
return r;
}
static double speedA(const GarunsFlow_c &r) { return r.sen;}
double BW_test;
void ode_system( const state_type &x , state_type &dxdt , const double t )
{
const GarunsFlow_c g_flow = GarunsFlow(x);
dxdt[A] = speedA(g_flow);
BW_test=g_flow.BW;
}
void write_ode( const state_type &x , const double t )
{
cout <<t<<'\t'<<x[A]<<'\t'<<BW_test << endl;
}
int main(int argc, char **argv)
{
state_type x = { 0.001 }; // initial conditions
typedef dense_output_runge_kutta<controlled_runge_kutta<runge_kutta_dopri5<state_type> > > stepper_type;
integrate_const(stepper_type(), ode_system, x, 0.0, 10.0, 1.0,write_ode);
}
chỉ có góp ý đấy thôi, biết có sai gì không, gạch đá xin nhận.
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?