33template <
int X,
int U>
34using WithInputDerivative = std::function<
35 Eigen::Vector<double, X>(
const Eigen::Vector<double, X>&,
const Eigen::Vector<double, U>&)>;
38using WithoutInputDerivative =
39 std::function<Eigen::Vector<double, X>(
const Eigen::Vector<double, X>&)>;
42using TimeVariantDerivative =
43 std::function<Eigen::Vector<double, Y>(
const double&,
const Eigen::Vector<double, Y>&)>;
58template <
int X,
int U>
59Eigen::Vector<double, X> euler_with_input(
60 const WithInputDerivative<X, U>& f,
const Eigen::Vector<double, X>& x,
61 const Eigen::Vector<double, U>& u,
const double& h
63 Eigen::Vector<double, X> k1 = f(x, u);
81Eigen::Vector<double, X> euler_without_input(
82 const WithoutInputDerivative<X>& f,
const Eigen::Vector<double, X>& x,
const double& h
84 Eigen::Vector<double, X> k1 = f(x);
103Eigen::Vector<double, Y> euler_time_variant(
104 const TimeVariantDerivative<Y>& f,
const double& t,
const Eigen::Vector<double, Y>& y,
107 Eigen::Vector<double, Y> k1 = f(t, y);
126template <
int X,
int U>
127Eigen::Vector<double, X> RK2_with_input(
128 const WithInputDerivative<X, U>& f,
const Eigen::Vector<double, X>& x,
129 const Eigen::Vector<double, U>& u,
const double& h
131 Eigen::Vector<double, X> k1 = f(x, u);
132 Eigen::Vector<double, X> k2 = f(x + h * 0.5 * k1, u);
151Eigen::Vector<double, X> RK2_without_input(
152 const WithoutInputDerivative<X>& f,
const Eigen::Vector<double, X>& x,
const double& h
154 Eigen::Vector<double, X> k1 = f(x);
155 Eigen::Vector<double, X> k2 = f(x + h * 0.5 * k1);
175Eigen::Vector<double, Y> RK2_time_variant(
176 const TimeVariantDerivative<Y>& f,
const double& t,
const Eigen::Vector<double, Y>& y,
179 Eigen::Vector<double, Y> k1 = f(t, y);
180 Eigen::Vector<double, Y> k2 = f(t + h * 0.5, y + h * 0.5 * k1);
201template <
int X,
int U>
202Eigen::Vector<double, X> RK4_with_input(
203 const WithInputDerivative<X, U>& f,
const Eigen::Vector<double, X>& x,
204 const Eigen::Vector<double, U>& u,
const double& h
206 Eigen::Vector<double, X> k1 = f(x, u);
207 Eigen::Vector<double, X> k2 = f(x + h * 0.5 * k1, u);
208 Eigen::Vector<double, X> k3 = f(x + h * 0.5 * k2, u);
209 Eigen::Vector<double, X> k4 = f(x + h * k3, u);
211 return x + h / 6.0 * (k1 + 2.0 * k2 + 2.0 * k3 + k4);
230Eigen::Vector<double, X> RK4_without_input(
231 const WithoutInputDerivative<X>& f,
const Eigen::Vector<double, X>& x,
const double& h
233 Eigen::Vector<double, X> k1 = f(x);
234 Eigen::Vector<double, X> k2 = f(x + h * 0.5 * k1);
235 Eigen::Vector<double, X> k3 = f(x + h * 0.5 * k2);
236 Eigen::Vector<double, X> k4 = f(x + h * k3);
238 return x + h / 6.0 * (k1 + 2.0 * k2 + 2.0 * k3 + k4);
258Eigen::Vector<double, Y> RK4_time_variant(
259 const TimeVariantDerivative<Y>& f,
const double& t,
const Eigen::Vector<double, Y>& y,
262 Eigen::Vector<double, Y> k1 = f(t, y);
263 Eigen::Vector<double, Y> k2 = f(t + h * 0.5, y + h * 0.5 * k1);
264 Eigen::Vector<double, Y> k3 = f(t + h * 0.5, y + h * 0.5 * k2);
265 Eigen::Vector<double, Y> k4 = f(t + h, y + h * k3);
267 return y + h / 6.0 * (k1 + 2.0 * k2 + 2.0 * k3 + k4);