14namespace smooth::feedback {
31 using smooth::utils::zip;
32 static constexpr auto Nx = std::invoke_result_t<
decltype(xfun),
double>::SizeAtCompileTime;
34 static_assert(Nx > 0,
"Static size required");
36 const auto N = m.N_ivals();
38 Eigen::VectorXd ival_errs(N);
41 for (
auto ival = 0u, M = 0u; ival < N; M += m.N_colloc_ival(ival), ++ival) {
42 const auto Kext = m.N_colloc_ival(ival);
45 Eigen::Matrix<double, Nx, -1> Fval(Nx, Kext + 1);
46 Eigen::Matrix<double, Nx, -1> Xval(Nx, Kext + 1);
47 for (
const auto & [j, tau] : zip(std::views::iota(0u, Kext + 1), m.interval_nodes(ival))) {
48 const double tj = t0 + (tf - t0) * tau;
51 const auto Xj = xfun(tj);
52 const auto Uj = ufun(tj);
55 Fval.col(j) = f(tj, Xj, Uj);
62 const Eigen::MatrixXd Xval_est =
63 Xval.col(0).replicate(1, Kext) + (tf - t0) * Fval.leftCols(Kext) * m.interval_intmat(ival);
66 Eigen::VectorXd e_abs = (Xval_est - Xval.rightCols(Kext)).colwise().norm();
67 Eigen::VectorXd e_rel = e_abs / (1. + Xval.rightCols(Kext).colwise().norm().maxCoeff());
70 ival_errs(ival) = e_rel.maxCoeff();
MeshType is a specialization of Mesh.
Eigen::VectorXd mesh_dyn_error(auto &&f, const MeshType auto &m, const double t0, const double tf, auto &&xfun, auto &&ufun)
Calculate relative dynamics errors for each interval in mesh.
Refinable Legendre-Gauss-Radau mesh of time interval [0, 1].