13 const auto d = curvature.rows();
14 if (!d || curvature.cols() != d || !curvature.allFinite() || !(h > 0) ||
16 (curvature - curvature.transpose()).norm() >
17 1e-12 * std::max(1., curvature.norm()))
18 throw std::invalid_argument(
19 "Finite symmetric fitting curvature and positive duration "
21 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eigen(
22 .5 * (curvature + curvature.transpose()));
23 if (eigen.info() != Eigen::Success || !eigen.eigenvalues().allFinite())
24 throw std::runtime_error(
25 "Frequency-fitted curvature eigensolve failed");
26 Eigen::VectorXd coupling(d);
27 double logarithm = 0, caustic = std::numeric_limits<double>::infinity();
28 for (Eigen::Index i = 0; i < d; ++i) {
29 const double lambda = eigen.eigenvalues()[i],
30 x = .5 * h * std::sqrt(std::abs(lambda));
31 if (!std::isfinite(
x))
32 throw std::overflow_error(
"Unrepresentable fitted phase");
35 if (!(
x < std::numbers::pi / 2))
36 throw std::domain_error(
37 "Fitted unstable link reaches its reference caustic");
38 if (
x > 0) ratio =
x / std::sin(
x);
39 caustic = std::min(caustic, std::numbers::pi - 2 *
x);
41 ratio =
x < 20 ?
x / std::sinh(
x)
42 : 2 *
x * std::exp(-
x) / (-std::expm1(-2 *
x));
44 coupling[i] = ratio * ratio / h;
45 if (!(coupling[i] > 0) || !std::isfinite(coupling[i]))
46 throw std::overflow_error(
47 "Unrepresentable positive fitted kinetic coupling");
48 logarithm += std::log(coupling[i]);
50 Eigen::MatrixXd l = eigen.eigenvectors() * coupling.asDiagonal() *
51 eigen.eigenvectors().transpose();
52 l = (.5 * l + .5 * l.transpose()).eval();
53 if (!l.allFinite() || !std::isfinite(logarithm))
54 throw std::overflow_error(
"Nonfinite fitted kinetic link");
55 return {l, l, logarithm, h, caustic, {}};