#include
#include
// include Boost's odeint
#include
// [[Rcpp::depends(BH)]]
using namespace Rcpp;
using namespace std;
using namespace boost::numeric::odeint;
typedef boost::array< double ,5 > state_type;
typedef boost::array< double ,4 > params_type;
std::vector x_result; // to store results
std::vector t_result; // to store time steps
bool inSet(int value, std ::vector set){
for(int i : set){
if(value == i){
return true;
}
}
return false;
}
void rhs( const state_type &x , state_type &dxdt , const double t, double b, NumericMatrix hazT) {
double hazJ = hazT(t,0);
double hazY = hazT(t,1);
double hazE = hazT(t,2);
double hazR = hazT(t,3);
double fec = b * (inSet(t, {4, 16, 28, 40, 52}) ? 1 : 0);
double mat = inSet(t, {3, 15, 27, 39, 51}) ? 1 : 0;
dxdt[0] = (fec * x[3]) - (hazJ * x[0]) - (mat * x[0]);
dxdt[1] = (mat * x[0]) - (hazY * x[1]) - (mat * x[1]);
dxdt[2] = (mat * x[0]) - (hazY * x[2]) - (mat * x[2]);
dxdt[3] = (mat * x[1]) - (hazE * x[3]);
dxdt[4] = (mat * x[2]) - (hazR * x[4]);
}
void write_cout( const state_type &x , const double t ) {
// use Rcpp's stream
//Rcpp::Rcout
Подробнее здесь: https://stackoverflow.com/questions/786 ... -step-boos