Alexandria  2.14.1
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
linear.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2020 Euclid Science Ground Segment
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation; either version 3.0 of the License, or (at your option)
7  * any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
29 
30 namespace Euclid {
31 namespace MathUtils {
32 
35  for (size_t i=0; i<x.size()-1; i++) {
36  double coef1 = (y[i+1]-y[i]) / (x[i+1]-x[i]);
37  double coef0 = y[i] - coef1*x[i];
38  functions.push_back(std::shared_ptr<Function>(new Polynomial{{coef0,coef1}}));
39  }
40  return std::unique_ptr<Function>(new Piecewise{x, std::move(functions)});
41 }
42 
43 } // End of MathUtils
44 } // end of namespace Euclid
std::unique_ptr< Function > linearInterpolation(const std::vector< double > &x, const std::vector< double > &y)
Performs linear interpolation for the given set of data points.
Definition: linear.cpp:33
Represents a polynomial function.
Definition: Polynomial.h:43
T push_back(T...args)
T move(T...args)
T size(T...args)
STL class.
Represents a piecewise function.
Definition: Piecewise.h:48