#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "cubic_spline.h"
#include "mbs_1D_array.h"
#include "mbs_matrix.h"
#include "mbs_message.h"
Functions | |
CubicSpline * | cubic_spline_new_from_file (const char *filename) |
Load the coefficient of the cubic splines from a file. More... | |
int | cubic_spline_get_index (CubicSpline *cs, double x_in) |
Retrieve the index (starting at zero) in the spline coefficient table corresponding to the specified coordinate. More... | |
double | cubic_spline_comp_value (CubicSpline *cs, double x_in, int index) |
Compute the value of the cubic spline at the specified coordinate. More... | |
double | cubic_spline_comp_firstder (CubicSpline *cs, double x_in, int index) |
Compute the value of the first derivative of the cubic spline at the specified coordinate. More... | |
double | cubic_spline_comp_secondder (CubicSpline *cs, double x_in, int index) |
Compute the value of the second derivative of the cubic spline at the specified coordinate. More... | |
void | cubic_spline_comp_val_and_der (CubicSpline *cs, double x_in, int index, double *y, double *yp, double *ypp) |
Compute the value of the cubic spline and its first and second derivatives at the specified coordinate. More... | |
void | cubic_spline_delete (CubicSpline *cs) |
Free the memory of cubic spline. More... | |
This c file implements utilities functions about cubic spline interpolation.
Creation date: 2022
(c) Universite catholique de Louvain
double cubic_spline_comp_firstder | ( | CubicSpline * | cs, |
double | x_in, | ||
int | index | ||
) |
Compute the value of the first derivative of the cubic spline at the specified coordinate.
cs | cubic spline. |
x_in | evaluated coordinate. |
index | corresponding to the evaluated coordinate. Use cubic_spline_get_index to get the index corresponding to the coordinate or use -99 to let the function evaluating the index by itself. Other negative values are invalid index. |
double cubic_spline_comp_secondder | ( | CubicSpline * | cs, |
double | x_in, | ||
int | index | ||
) |
Compute the value of the second derivative of the cubic spline at the specified coordinate.
cs | cubic spline. |
x_in | evaluated coordinate. |
index | corresponding to the evaluated coordinate. Use cubic_spline_get_index to get the index corresponding to the coordinate or use -99 to let the function evaluating the index by itself. Other negative values are invalid index. |
void cubic_spline_comp_val_and_der | ( | CubicSpline * | cs, |
double | x_in, | ||
int | index, | ||
double * | y, | ||
double * | yp, | ||
double * | ypp | ||
) |
Compute the value of the cubic spline and its first and second derivatives at the specified coordinate.
cs | cubic spline. |
x_in | evaluated coordinate. |
index | corresponding to the evaluated coordinate. Use cubic_spline_get_index to get the index corresponding to the coordinate or use -99 to let the function evaluating the index by itself. Ohter negative value are invalid index. |
y | a pointer to the memory where to store the value of the cubic spline. |
yp | a pointer to the memory where to store the 1st derivative. |
ypp | a pointer to the memory where to store the 2nd derivative. |
double cubic_spline_comp_value | ( | CubicSpline * | cs, |
double | x_in, | ||
int | index | ||
) |
Compute the value of the cubic spline at the specified coordinate.
cs | cubic spline. |
x_in | evaluated coordinate. |
index | corresponding to the evaluated coordinate. Use cubic_spline_get_index to get the index corresponding to the coordinate or use -99 to let the function evaluating the index by itself. Other negative values are invalid index. |
void cubic_spline_delete | ( | CubicSpline * | cs | ) |
Free the memory of cubic spline.
cs | cubic spline to be deleted. |
int cubic_spline_get_index | ( | CubicSpline * | cs, |
double | x_in | ||
) |
Retrieve the index (starting at zero) in the spline coefficient table corresponding to the specified coordinate.
The index is the lower value of the interval.
cs | cubic spline. |
x_in | coordinate for which to retrieve the index. |
CubicSpline* cubic_spline_new_from_file | ( | const char * | filename | ) |
Load the coefficient of the cubic splines from a file.
Allocate also the memory corresponding to this spline structure.
The file contains 5 columns, denoted: , , , , . Each column must be separated by a space character. Each line defines a segment. The signification of each column is:
The spline is computed as: with
The last line of the file must contains five column, even if only the first value is used as the end of the cubic spline interpolation range.
To generate the input file, an example of Python script is provided with the sources of MBsysC. The file named cubic_spline_compute_coefficients.py
is located in the folder MBsysC/scripts
.
[in] | filename | File name (with the path and extension) that contains the coefficients of the spline |