25 inline void spline(
const double t[],
const double y[],
const int n,
26 const double yp1,
const double ypn,
double y2[]) {
28 double p, qn, sig, un;
29 std::vector<double> u;
37 u[0] = (3.0 / (t[1] - t[0])) * ((y[1] - y[0]) / (t[1] - t[0]) - yp1);
40 for (i = 1; i <= n - 2; i++) {
41 sig = (t[i] - t[i - 1]) / (t[i + 1] - t[i - 1]);
42 p = sig * y2[i - 1] + 2.0;
43 y2[i] = (sig - 1.0) / p;
44 u[i] = (y[i + 1] - y[i]) / (t[i + 1] - t[i]) -
45 (y[i] - y[i - 1]) / (t[i] - t[i - 1]);
46 u[i] = (6.0 * u[i] / (t[i + 1] - t[i - 1]) - sig * u[i - 1]) / p;
53 un = (3.0 / (t[n - 1] - t[n - 2])) *
54 (ypn - (y[n - 1] - y[n - 2]) / (t[n - 1] - t[n - 2]));
56 y2[n - 1] = (un - qn * u[n - 2]) / (qn * y2[n - 2] + 1.0);
58 for (k = n - 2; k >= 0; k--) {
59 y2[k] = y2[k] * y2[k + 1] + u[k];
78 inline bool splpos(
const double xa[],
const double ya[],
const double y2a[],
79 const int n,
const double x,
double *y) {
85 while (khi - klo > 1) {
94 h = xa[khi] - xa[klo];
99 a = (xa[khi] - x) / h;
100 b = (x - xa[klo]) / h;
102 a * ya[klo] + b * ya[khi] +
103 ((a * a * a - a) * y2a[klo] + (b * b * b - b) * y2a[khi]) * (h * h) / 6.0;
122 inline bool splvel(
const double xa[],
const double ya[],
const double y2a[],
123 const int n,
const double x,
double *y) {
129 while (khi - klo > 1) {
130 k = (khi + klo) >> 1;
138 h = xa[khi] - xa[klo];
143 a = (xa[khi] - x) / h;
144 b = (x - xa[klo]) / h;
145 *y = (-1 / h) * ya[klo] + (1 / h) * ya[khi] +
146 ((3 * a * a - 1) * y2a[klo] * (-1 / h) +
147 (3 * b * b - 1) * y2a[khi] * (1 / h)) *
167 inline bool splacc(
const double xa[],
const double ya[],
const double y2a[],
168 const int n,
const double x,
double *y) {
174 while (khi - klo > 1) {
175 k = (khi + klo) >> 1;
183 h = xa[khi] - xa[klo];
190 a = (xa[khi] - x) / h;
191 b = (x - xa[klo]) / h;
192 *y = y2a[klo] * a + y2a[khi] * b;
bool splacc(const double xa[], const double ya[], const double y2a[], const int n, const double x, double *y)
Calculates acceleration of spline.
Definition: cubic_impl.hpp:167
bool splvel(const double xa[], const double ya[], const double y2a[], const int n, const double x, double *y)
Calculates velocity of spline.
Definition: cubic_impl.hpp:122
void spline(const double t[], const double y[], const int n, const double yp1, const double ypn, double y2[])
Calculates second derivatives at tabulated points.
Definition: cubic_impl.hpp:25
bool splpos(const double xa[], const double ya[], const double y2a[], const int n, const double x, double *y)
Calculates position of spline.
Definition: cubic_impl.hpp:78