odesolver.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #include "utils.hpp"
14 
15 namespace target {
16 
17  // Type definition
18  using odefunc = std::function<arma::mat(arma::mat input,
19  arma::mat x,
20  arma::mat theta)>;
21 
22  arma::mat interpolate(const arma::mat &input, // first column is time
23  double tau, // Time-step
24  bool locf = false); // Last-observation-carried forward
25  // otherwise linear interpolation
29  class Solver {
30  protected:
31  odefunc F;
32 
33  public:
34  explicit Solver(odefunc F) {
35  this->F = F;
36  }
37  virtual ~Solver() {}
38 
39  virtual arma::mat solve(const arma::mat &input,
40  arma::mat init,
41  arma::mat theta) = 0;
42  arma::mat solveint(const arma::mat &input,
43  arma::mat init,
44  arma::mat theta,
45  double tau = 1.0e-1,
46  bool reduce = true);
47  };
48 
52  class RK4 : public Solver { // Basic 4th order Runge-Kutta solver
53  public:
54  using Solver::Solver;
55 
56  arma::mat solve(const arma::mat &input, arma::mat init, arma::mat theta);
57  };
58 
59  } // namespace target
Various utility functions and constants.