help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] gsl_linear_interp example


From: Daniel J Farrell
Subject: Re: [Help-gsl] gsl_linear_interp example
Date: Wed, 6 Jun 2007 23:39:12 +0100

Hello,

Ended up figuring it out.

Cheers,

Dan.

For future reference:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <gsl/gsl_interp.h>

int main (void)
{
      //sample data
      double x[4] = { 1970, 1980, 1990, 2000 };
      double y[4] = {   12,   11,   14,   13 };

      //inialise and allocate the gsl objects
gsl_interp *interpolation = gsl_interp_alloc (gsl_interp_linear,n);
      gsl_interp_init(interpolation, x, y, n);
      gsl_interp_accel * accelerator =  gsl_interp_accel_alloc();

      //get interpolation for x = 1981
double value = gsl_interp_eval(interpolation, x, y, 1981, accelerator);

      printf("\n%g",value);

      //output:
      //11.3

  return 0;
}

On 6 Jun 2007, at 14:42, Daniel J Farrell wrote:

Hello,

I am trying to find example code on how to do a linear interpolation. So far I can allocate and initalise the gsl_interp object, but I get a bit stuck when I need to query it for interpolation values; do I have to use an accelerator?

Any advice?

Regards,

Dan.

___

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <gsl/gsl_spline.h>
#include <gsl/gsl_interp.h>

int main (void)
{
  unsigned n = 4;
  double x[n] = { 1970, 1980, 1990, 2000 };
  double y[n] = {   12,   11,   14,   13 };

  //interpolation
  gsl_interp *interp = gsl_interp_alloc(gsl_interp_linear,n);
  gsl_interp_init(interp, x, y, n);


  //get interpolation for x = 1981 here...


  gsl_interp_free(interp);
  return 0;
}





_______________________________________________
Help-gsl mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/help-gsl





reply via email to

[Prev in Thread] Current Thread [Next in Thread]