[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-gsl] Interpolated Values as function return
From: |
Foivos Diakogiannis |
Subject: |
Re: [Help-gsl] Interpolated Values as function return |
Date: |
Tue, 12 Nov 2013 05:23:02 +1100 |
Dear all,
This is not a sophisticated example (I am a humble astronomer, not a
software engineer) but may be of help to Klaus.
Say you have initiated interpolation at some point in your code, and you
wan't to use this interpolation as a function in ta numerical integration
scheme.
// Define parameters for Function
struct gsl_params{
gsl_spline * splineE; // Pointer to spline GSL definitions.
gsl_interp_accel * accC; //accelerator for spline interpetation
};
// Degine kernel (function) that goes into the integration scheme.
double gsl_kernel(double r, void *p)
{
gsl_params * params = reinterpret_cast<gsl_params * > (p);
return
gsl_spline_eval (params->splineE, r, params->accC);
};
// Actual numerical integration function. Takes as argument the params
structure.
double gsl_integral( gsl_params * myparams){
gsl_integration_workspace * w = gsl_integration_workspace_alloc
(1000);
double result, error;
gsl_function func { gsl_kernel, myparams}; // Function that is the
wrapper of the interpolation
gsl_integration_qags (&func, 0, 1, 0, 1e-7, 1000, w, &result,
&error);
return result;
};
On Tue, Nov 12, 2013 at 5:04 AM, Rhys Ulerich <address@hidden>wrote:
> > But searching the internet told me, that it is not possible to get the
> > address from a member function in C++!?
>
> I believe that's true but have never looked in-depth, however,...
>
> > ...you have to give the GSL function the address of the member
> > function, in that case the foo::operator()().
>
> I'm suggesting storing a pointer to an instance in
> gsl_function.params. Then, in the function, retrieving that pointer,
> casting it to the object type, and calling a method on the instance.
>
> > Uh, what do you mean with 'it definitly _does not_complie'? So my idea is
> > plain wrong?
>
> Not at all. Just that my sample code wouldn't build.
>
> - Rhys
>
>