Dear Ladies and Gentlemen,

I am so far quite confident with the basic usage of the GSL but now I wonder e.g. about combining methods. In the appendix I have written a class to initialize a spline, given two vectors as the x and y data set.

Fortnunetly, the GSL provides numerical methods, e.g. to integrate the interpolated data set.

But what if I want to use the interpolated data set as input for another GSL Routine, like root finding, Fourier Transform, odeint, etc.

I have put the return statement of the interpolation routine in the GSL function provided for the GSL method.

In the appended file I define (wrongly, it does not work) a function from line 33 to 36 to return the interpolated value and this should be use as required in line 41. But what about the params?

I hope you can help me.

Kind regards,

    Klaus Huthmacher.
#include <iostream>
#include <memory>
#include <vector>

#include "gsl/gsl_math.h"
#include "gsl/gsl_spline.h"

class foo
{
	public:
		foo(std::vector<double>, std::vector<double>);
		double operator()(double);

	private:
		std::vector<double> _x, _y;
		std::unique_ptr<gsl_interp_accel,void(*)(gsl_interp_accel*)> acc;
		std::unique_ptr<gsl_spline,void(*)(gsl_spline*)> spline;
};

foo::foo(std::vector<double> x, std::vector<double> y):
_x(x), _y(y),
acc(gsl_interp_accel_alloc(),gsl_interp_accel_free),
spline(gsl_spline_alloc(gsl_interp_cspline, _x.size()),gsl_spline_free)
{
	gsl_spline_init(spline.get(), _x.data(), _y.data(), _x.size());
}

auto foo::operator()(double x) -> double
{
	return gsl_spline_eval(spline.get(), x, acc.get());
}

auto function(double x, void* params) -> double
{
	return foo(x);
}

int main()
{
	gsl_function F;
	F.function = &function;

}

<<attachment: huthmacher.vcf>>

Reply via email to