Zephyr Scientific Library (zscilib)
|
Go to the documentation of this file.
9 #include <zephyr/kernel.h>
19 if ((t < 0.0f) || (t > 1.0f)) {
25 *v = (1.0f - t) * v0 + t * v1;
36 unsigned int idx_upper;
38 unsigned int idx_lower;
53 order = (xy[n - 1].
x >= xy[0].
x);
56 if ((x > xy[n - 1].x && order) || (x < xy[n - 1].
x && !order)) {
61 }
else if ((x < xy[0].x && order) || (x > xy[0].
x && !order)) {
70 while (idx_upper - idx_lower > 1) {
71 idx_mid = (idx_upper + idx_lower) >> 1;
72 if ((x >= xy[idx_mid].x && order) ||
73 (x <= xy[idx_mid].
x && !order)) {
86 }
else if (x == xy[n - 1].x) {
107 delta = xy3->
x - xy1->
x;
108 if (delta < 1E-6F && -delta < 1E-6F) {
115 if ((x2 < xy1->x) || (x2 > xy3->
x)) {
121 *y2 = x2 >= (xy1->
x * 1.5f) ? xy3->
y : xy1->
y;
162 delta = xy3->
x - xy1->
x;
163 if (delta < 1E-6F && -delta < 1E-6F) {
170 if ((x2 < xy1->x) || (x2 > xy3->
x)) {
182 *y2 = ((x2 - xy1->
x) * (xy3->
y - xy1->
y)) / (xy3->
x - xy1->
x) + xy1->
y;
223 delta = xy3->
x - xy1->
x;
224 if (delta < 1E-6F && -delta < 1E-6F) {
231 min = xy1->
y < xy3->
y ? xy1->
y : xy3->
y;
232 max = xy1->
y < xy3->
y ? xy3->
y : xy1->
y;
233 if ((y2 < min) || (y2 > max)) {
245 *x2 = ((xy3->
y - y2) * xy1->
x + (y2 - xy1->
y) *
246 xy3->
x) / (xy3->
y - xy1->
y);
279 if (yp1 > 0.99e30f) {
280 xyc[0].
y2 = u[0] = 0.0f;
283 u[0] = (3.0f / (xyc[1].
x - xyc[0].
x)) *
284 ((xyc[1].
y - xyc[0].
y) / (xyc[1].x - xyc[0].x) - yp1);
287 for (i = 1; i < n - 1; i++) {
291 sigma = x_i_im1 / x_ip1_im1;
292 p = sigma * xyc[i - 1].
y2 + 2.0f;
293 xyc[i].
y2 = (sigma - 1.0f) / p;
294 u[i] = (xyc[i + 1].
y - xyc[i].
y) / (xyc[i + 1].x - xyc[i].x) -
295 (xyc[i].
y - xyc[i - 1].
y) / (x_i_im1);
296 u[i] = (6.0f * u[i] / (x_ip1_im1) - sigma * u[i - 1]) / p;
299 if (ypn > 0.99e30f) {
303 un = (3.0f / (xyc[n - 1].
x - xyc[n - 2].
x)) *
304 (ypn - (xyc[n - 1].
y -
305 xyc[n - 2].
y) / (xyc[n - 1].x - xyc[n - 2].x));
308 xyc[n - 1].
y2 = (un - qn * u[n - 2]) / (qn * xyc[n - 2].y2 + 1.0f);
310 for (k = n - 2; k >= 0; k--) {
311 xyc[k].
y2 = xyc[k].
y2 * xyc[k + 1].
y2 + u[k];
348 if (xyc[pklo].x <= x && xyc[pkhi].x > x) {
355 while (khi - klo > 1) {
358 k = (khi + klo) >> 1;
381 h = xyc[khi].
x - xyc[klo].
x;
389 a = (xyc[khi].
x - x) / h;
390 b = (x - xyc[klo].
x) / h;
393 *y = a * xyc[klo].
y + b * xyc[khi].
y +
394 ((a * a * a - a) * xyc[klo].y2 + (b * b * b - b) *
395 xyc[khi].
y2) * (h * h) / 6.0f;
int zsl_interp_lin_y(struct zsl_interp_xy *xy1, struct zsl_interp_xy *xy3, zsl_real_t x2, zsl_real_t *y2)
Linear (AKA 'piecewise linear') interpolation for Y between two points, based on zsl_real_ts.
int zsl_interp_lin_x(struct zsl_interp_xy *xy1, struct zsl_interp_xy *xy3, zsl_real_t y2, zsl_real_t *x2)
Linear (AKA 'piecewise linear') interpolation for X between two points, based on zsl_real_ts.
int zsl_interp_cubic_arr(struct zsl_interp_xyc xyc[], size_t n, zsl_real_t x, zsl_real_t *y)
Natural cubic spline interpolation between two points, based on zsl_real_ts.
int zsl_interp_nn(struct zsl_interp_xy *xy1, struct zsl_interp_xy *xy3, zsl_real_t x2, zsl_real_t *y2)
Nearest neighbour (AKA 'piecewise constant') interpolation based on zsl_real_ts.
API header file for interpolation functions in zscilib.
int zsl_interp_cubic_calc(struct zsl_interp_xyc xyc[], size_t n, zsl_real_t yp1, zsl_real_t ypn)
Calculates xyc[n].y2 for natural cubic spline interpolation, based on the assigned xyc[n]....
XY struct for cubic spline interpolation.
int zsl_interp_lerp(zsl_real_t v0, zsl_real_t v1, zsl_real_t t, zsl_real_t *v)
Calculates a number between two numbers using linear interpolation, where 't' is the interpolation fa...
zsl_real_t y2
Second derivative from the spline.
int zsl_interp_find_x(struct zsl_interp_xy xy[], size_t n, zsl_real_t x, int *idx)
Uses bisection to search the zsl_interp_xy array for the closest array position to 'x',...
API header file for zscilib.
int zsl_interp_nn_arr(struct zsl_interp_xy xy[], size_t n, zsl_real_t x, zsl_real_t *y)
Nearest neighbour (AKA 'piecewise constant') interpolation based on an array of zsl_real_ts.
int zsl_interp_lin_y_arr(struct zsl_interp_xy xy[], size_t n, zsl_real_t x, zsl_real_t *y)
Linear (AKA 'piecewise linear') interpolation for Y between two points, based on zsl_real_ts.
XY struct for nearest neighbour and linear interpolation.