29 real* p = malloc((n-1)*
sizeof(
real));
37 Y[0] = 3 * (f[1] - f[0]);
38 for(
int i=1; i<n-1; i++) {
39 Y[i] = 3 * (f[i+1] - f[i-1]);
41 Y[n-1] = 3 * (f[n-1] - f[n-2]);
48 for(
int i=1; i<n-1; i++) {
49 p[i] = 1 / (4 - p[i-1]);
50 Y[i] = (Y[i] - Y[i-1]) / (4 - p[i-1]);
52 Y[n-1] = (Y[n-1] - Y[n-2]) / (2 - p[n-2]);
56 for(
int i=n-2; i>-1; i--) {
57 D[i] = Y[i] - p[i] * D[i+1];
66 real* r = malloc((n-2)*
sizeof(
real));
70 Y[0] = 3 * (f[1] - f[n-1]);
71 for(
int i=1; i<n-1; i++) {
72 Y[i] = 3 * (f[i+1] - f[i-1]);
74 Y[n-1] = 3 * (f[0] - f[n-2]);
82 for(
int i=1; i<n-2; i++) {
83 dlast = dlast - l * r[i-1];
84 Y[n-1] = Y[n-1] - l * Y[i-1];
86 p[i] = 1 / (4 - p[i-1]);
87 r[i] = -r[i-1] / (4 - p[i-1]);
88 Y[i] = (Y[i] - Y[i-1]) / (4 - p[i-1]);
90 blast = 1.0 - l * p[n-3];
91 dlast = dlast - l * r[n-3];
92 Y[n-1] = Y[n-1] - l * Y[n-3];
94 p[n-2] = (1 - r[n-3]) / (4 - p[n-3]);
95 Y[n-2] = (Y[n-2] - Y[n-3]) / (4 - p[n-3]);
96 Y[n-1] = (Y[n-1] - blast * Y[n-2]) / (dlast - blast * p[n-2]);
100 D[n-2] = Y[n-2] - p[n-2] * D[n-1];
101 for(
int i=n-3; i>-1; i--) {
102 D[i] = Y[i] - p[i] * D[i+1] - r[i] * D[n-1];
114 c[(n-1)*4+1] = D[n-1];
115 c[(n-1)*4+2] = 3 * (f[0] - f[n-1]) - 2 * D[n-1] - D[0];
116 c[(n-1)*4+3] = 2 * (f[n-1] - f[0]) + D[n-1] + D[0];
120 for(
int i=0; i<n-1; i++) {
123 c[i*4+2] = 3 * (f[i+1] - f[i]) - 2*D[i] - D[i+1];
124 c[i*4+3] = 2 * (f[i] - f[i+1]) + D[i] + D[i+1];
void splineexpl(real *f, int n, int bc, real *c)
Calculate explicit cubic spline interpolation coefficients in 1D.