Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <array> 7 : #include <cstddef> 8 : #include <vector> 9 : 10 : namespace intrp { 11 : /*! 12 : * \ingroup NumericalAlgorithmsGroup 13 : * \brief A linear least squares solver 14 : * 15 : * A wrapper class for the gsl linear least squares solver which determines 16 : * the coefficients of best fit for a polynomial of order `Order` given a set 17 : * of data points `x_values` and `y_values` representing some function y(x). 18 : * The coefficients can be passed to \ref evaluate_polynomial for 19 : * interpolation. 20 : * 21 : * The form taking and returning vectors performs several fits in sequence, 22 : * reusing internal allocations for efficiency. 23 : * 24 : * The details of the linear least squares solver can be seen here: 25 : * [GSL documentation](https://www.gnu.org/software/gsl/doc/html/lls.html#). 26 : */ 27 : /// @{ 28 : template <size_t Order, typename T> 29 1 : std::array<double, Order + 1> linear_least_squares(const T& x_values, 30 : const T& y_values); 31 : template <size_t Order, typename T> 32 1 : std::vector<std::array<double, Order + 1>> linear_least_squares( 33 : const T& x_values, const std::vector<T>& y_values); 34 : /// @} 35 : } // namespace intrp