#pragma once #include "math.hpp" namespace matrix { template int integrate_rk4( Vector (*f)(Type, const Matrix &x, const Matrix & u), const Matrix & y0, const Matrix & u, Type t0, Type h, Matrix & y1 ) { // https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods Vector k1, k2, k3, k4; k1 = f(t0, y0, u); k2 = f(t0 + h/2, y0 + k1*h/2, u); k3 = f(t0 + h/2, y0 + k2*h/2, u); k4 = f(t0 + h, y0 + k3*h, u); y1 = y0 + (k1 + k2*2 + k3*2 + k4)*(h/6); return 0; } }; // namespace matrix