39 [[nodiscard]]
static Eigen::VectorX<Scalar>
calcCoefficients(
const Eigen::MatrixBase<DerivedX>& x,
const Eigen::MatrixBase<DerivedY>& y,
size_t polynomialDegree = 2)
41 auto effectiveDegree =
static_cast<Eigen::Index
>(std::min(polynomialDegree,
static_cast<size_t>(x.rows()) - 1));
44 Eigen::MatrixX<Scalar> H = Eigen::MatrixX<Scalar>(n, effectiveDegree + 1);
45 Eigen::ArrayX<Scalar> xpow = Eigen::ArrayX<Scalar>::Ones(x.rows());
46 for (
int i = 0; i < effectiveDegree + 1; i++)
48 H.col(i) = xpow.matrix();
52 return H.householderQr().solve(y);