I'm getting a 'gsl: interp.c:150: ERROR: interpolation error' with the following code. Some googling says that this error occurs when you try to extrapolate using the interp function but I don't see how that is happening here. Help would be greatly appreciated. Thanks.
The function randomground()
just returns a random number (double).
#define NSTEPS 100
int main()
{
int j, q, space = 1, refine = 100;
double xi = 0.0, tx[2*NSTEPS] = {0}, theight[2*NSTEPS] = {0};
double terrain[(int) (2*NSTEPS*100)] = {0};
double terrainsl[(int) (2*NSTEPS*100)] = {0};
for (j = 0; j < 2*NSTEPS; j++)
{
tx[j] = (double) j*space;
theight[j] = randomground();
}
gsl_interp_accel *acc = gsl_interp_accel_alloc();
gsl_spline *spline = gsl_spline_alloc(gsl_interp_akima, 2*NSTEPS);
gsl_spline_init(spline, tx, theight, 2*NSTEPS);
for (q = 0; q< 2*NSTEPS*100; q++)
{
terrain[q] = gsl_spline_eval(spline,xi,acc);
terrainsl[q] = gsl_spline_eval_deriv(spline,xi,acc);
xi = xi+(double) space/refine;
}
return 0;
}