/*
call-seq:
interpolate(x_values)
interpolate(a_number)
Computes interpolated values of the data contained in +f+ and
returns a Function object holding both +x_values+ and the computed
Y values. +x_values+ will be sorted if necessary.
With the second form, specify only the number of points, and
the function will construct the appropriate vector with equally spaced
points within the function range.
*/
static VALUE function_interpolate(VALUE self, VALUE x_values)
{
if(NUMERIC(x_values))
{
/* we're in the second case, although I sincerely doubt it would
come useful
*/
long size,i;
/* we make sure the function is sorted */
function_ensure_sorted(self);
double * data;
double x_min;
double x_max;
data = Dvector_Data_for_Read(get_x_vector(self), &size);
x_min = *data;
x_max = *(data + size -1);
x_values = rb_funcall(cDvector, idNew, 1, x_values);
data = Dvector_Data_for_Write(x_values, &size);
for(i = 0;i < size; i++)
data[i] = x_min + ((x_max - x_min)/((double) (size-1))) * i;
}
if(! IS_A_DVECTOR(x_values))
rb_raise(rb_eArgError, "x_values should be a Dvector or a number");
else
{
/* sort x_values */
if(! dvector_is_sorted(x_values))
rb_funcall(x_values, idSort,0);
VALUE y_values = function_compute_spline(self, x_values);
return rb_funcall(cFunction, idNew, 2, x_values, y_values);
}
return Qnil;
}