7 #define WITHOUT_PIVOTING 0
8 #define WITH_PIVOTING 1
23 double dx_a, dx_b, dx_c, *
a, *
b, *c, *
r, *y2;
28 static char dbmsname[] =
"spline";
34 fprintf(stderr,
"**error:%s, n=%d < 3\n", dbmsname, n);
41 a = (
double *)malloc(n *
sizeof(
double));
42 b = (
double *)malloc(n *
sizeof(
double));
43 c = (
double *)malloc(n *
sizeof(
double));
44 r = (
double *)malloc(n *
sizeof(
double));
45 y2 = (
double *)malloc(n *
sizeof(
double));
47 for (
j = 0;
j < n;
j++) {
48 y2[
j] = (table +
j)->z;
51 for (
j = 0;
j < n;
j++) {
55 dx_a = (table +
j)->x - (table + jm1)->x;
57 fprintf(stderr,
"**error:%s, x[%d]=%g x[%d]=%g\n", dbmsname, jm1,
58 (table + jm1)->x,
j, (table +
j)->x);
62 dx_b = (table + jp1)->x - (table + jm1)->x;
64 fprintf(stderr,
"**error:%s, x[%d]=%g x[%d]=%g\n", dbmsname, jm1,
65 (table + jm1)->x, jp1, (table + jp1)->x);
71 dx_c = (table + jp1)->x - (table +
j)->x;
73 fprintf(stderr,
"**error:%s, x[%d]=%g x[%d]= %g\n", dbmsname,
j,
74 (table +
j)->x, jp1, (table + jp1)->x);
80 if (y1_bot > 0.99e+30) {
85 r[
j] = ((table + jp1)->y - (table +
j)->y) / dx_c - y1_bot;
87 }
else if (
j == n - 1) {
88 if (y1_top > 0.99e+30) {
93 r[
j] = y1_top - ((table +
j)->y - (table + jm1)->y) / dx_a;
99 r[
j] = ((table + jp1)->y - (table +
j)->y) / dx_c -
100 ((table +
j)->y - (table + jm1)->y) / dx_a;
104 if (y1_bot > 0.99e+30) {
105 if (y1_top > 0.99e+30) {
113 if (y1_top > 0.99e+30) {
122 for (
j = 0;
j < n;
j++) {
123 (table +
j)->z = y2[
j];
155 a = ((table + 1)->x - xx) / dx;
156 b = (xx - table->
x) / dx;
158 ans =
a * table->
y +
b * (table + 1)->y +
159 ((
a *
a *
a -
a) * (table)->z + (
b *
b *
b -
b) * (table + 1)->z) * dx *
void tridiag(int n, double *a, double *b, double *c, double *r, double *u, int pivot_type)
double splint(double xx, struct float_triplet *table, double dx)
void spline(int n, struct float_triplet *table, double y1_bot, double y1_top)