Go to the documentation of this file.
43 #ifndef INCLUDE_CUBIC_SPLINE_HPP
44 #define INCLUDE_CUBIC_SPLINE_HPP
93 const T DYDX1,
const T DYDXN)
113 Exception e(
"Must call initialize() first");
144 Exception e(
"Must call initialize() first");
147 if (x <
X[0] || x >
X[
N - 1])
150 "Input value is outside range determined by initialize()");
160 for (i = 1; i <
N; i++)
166 if (
X[i - 1] < x && x <=
X[i])
189 Exception e(
"Must call initialize() first");
197 for (i = 0; i < n; i++)
199 if (x[i] <
X[0] || x[i] >
X[
N - 1])
202 std::string(
"Input value at index ") +
204 std::string(
" is outside range determined by initialize()"));
209 if (k <
N && x[i] >
X[k])
214 else if (k > 0 && x[i] <
X[k - 1])
216 while (x[i] <=
X[k - 1])
224 else if (x[i] ==
X[k - 1])
238 int size()
const {
return S.size(); }
253 void build(
const std::vector<T>& x,
const std::vector<T>&
y,
bool fixEnds)
263 N = (x.size() <
y.size() ? x.size() :
y.size());
266 Exception e(
"Input data array(s) empty");
271 X = std::vector<T>(
N);
272 Y = std::vector<T>(
N);
273 S = std::vector<T>(
N);
278 for (i = 1; i <
N; i++)
280 if (x[i - 1] >= x[i])
282 Exception e(
"Input data array X is not strictly increasing");
292 for (i = 0; i <
N; i++)
304 fd1 = ((
Y[1] -
Y[0]) / (dx1 * dx1) - (
Y[2] -
Y[0]) / (dx2 * dx2)) /
305 (T(1) / dx1 - T(1) / dx2);
307 dx1 =
X[
N - 2] -
X[
N - 1];
308 dx2 =
X[
N - 3] -
X[
N - 1];
309 fdN = ((
Y[
N - 2] -
Y[
N - 1]) / (dx1 * dx1) -
310 (
Y[
N - 3] -
Y[
N - 1]) / (dx2 * dx2)) /
311 (T(1) / dx1 - T(1) / dx2);
315 S[0] = T(6) * ((
Y[1] -
Y[0]) / (
X[1] -
X[0]) -
fd1);
317 T(6) * (
fdN + (
Y[
N - 2] -
Y[
N - 1]) / (
X[
N - 1] -
X[
N - 2]));
320 for (i = 1; i <
N - 1; i++)
323 (
Y[i - 1] / (
X[i] -
X[i - 1]) -
324 Y[i] * (T(1) / (
X[i] -
X[i - 1]) + T(1) / (
X[i + 1] -
X[i])) +
325 Y[i + 1] / (
X[i + 1] -
X[i]));
329 A[0] = T(2) * (
X[1] -
X[0]);
330 A[1] = T(1.5) * (
X[1] -
X[0]) + T(2) * (
X[2] -
X[1]);
331 S[1] -= T(0.5) *
S[0];
332 for (i = 2; i <
N - 1; i++)
334 dx1 = (
X[i] -
X[i - 1]) / A[i - 1];
335 A[i] = T(2) * (
X[i + 1] -
X[i - 1]) - dx1 * (
X[i] -
X[i - 1]);
336 S[i] -= dx1 *
S[i - 1];
338 dx1 = (
X[
N - 1] -
X[
N - 2]) / A[
N - 2];
339 A[
N - 1] = (T(2) - dx1) * (
X[
N - 1] -
X[
N - 2]);
340 S[
N - 1] -= dx1 *
S[
N - 2];
343 S[
N - 1] /= A[
N - 1];
344 for (i =
N - 2; i >= 0; i--)
346 S[i] -= (
X[i + 1] -
X[i]) *
S[i + 1];
356 T dxr(
X[k] - x), dxl(x -
X[k - 1]), dx(
X[k] -
X[k - 1]);
357 return ((dxl * (
Y[k] -
S[k] * dx * dx / T(6)) +
358 (
S[k - 1] * dxr * dxr * dxr +
S[k] * dxl * dxl * dxl) / T(6) +
359 dxr * (
Y[k - 1] -
S[k - 1] * dx * dx / T(6))) /
int N
size of the arrays X,Y,S
Cubic spline interpolation.
std::vector< T > evaluate(const std::vector< T > &x)
std::string asString(IonexStoreStrategy e)
Convert a IonexStoreStrategy to a whitespace-free string name.
bool testLimits(const T &x, T &y)
void initialize(const std::vector< T > &X, const std::vector< T > &Y)
void build(const std::vector< T > &x, const std::vector< T > &y, bool fixEnds)
page HOWTO subpage DoxygenGuide Documenting Your Code page DoxygenGuide Documenting Your Code todo Flesh out this document section doctips Tips for Documenting When defining make sure that the prototype is identical between the cpp and hpp including both the namespaces and the parameter names for you have std::string as the return type in the hpp file and string as the return type in the cpp Doxygen may get confused and autolink to the cpp version with no documentation If you don t use the same parameter names between the cpp and hpp that will also confuse Doxygen Don t put type information in return or param documentation It doesn t really add anything and will often cause Doxygen to complain and not produce the documentation< br > use note Do not put a comma after a param name unless you mean to document multiple parameters< br/> the output stream</code >< br/> y
T fd1
Values of the derivative dy/dx at the first and last data points.
std::vector< T > X
Data arrays.
void initialize(const std::vector< T > &X, const std::vector< T > &Y, const T DYDX1, const T DYDXN)
int size() const
Return the current size of the second derivative array.
CubicSpline()
Empty constructor - NB must call initialize() before Eval().
#define GNSSTK_THROW(exc)
CubicSpline(const std::vector< T > &X, const std::vector< T > &Y)
T interpolate(const int k, const T x)
gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:38