-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspline.cpp
More file actions
76 lines (56 loc) · 2.51 KB
/
Copy pathspline.cpp
File metadata and controls
76 lines (56 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
Abraham Flores
Notre Dame Physics REU 2016
6/9/2016
Language C++
SPLINE INTERPOLATION:
*see header for details
*/
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <utility>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_spline.h>
#include <gsl/gsl_sf_laguerre.h>
#include "spline.h"
/*
Enter function required for evaluation here:
*/
namespace spline{
double CubicIntegrate(const double x[], const double y[], int n){
gsl_interp_accel *acc = gsl_interp_accel_alloc (); //Returns pointer to accelerator object, tracks state of lookups
const gsl_interp_type *t = gsl_interp_cspline;//Cubic Spline with periodic boundary conditions, result: piecewise cubic on each interval
gsl_spline *spline = gsl_spline_alloc (t,n);//Returns a pointer to a newly allocated interpolation object of type t for n size data-points
gsl_spline_init(spline, x, y, n);
double integral_value;
integral_value = gsl_spline_eval_integ(spline,x[0],x[n-1],acc);//Evaluate Integral
gsl_spline_free (spline);
gsl_interp_accel_free (acc);
return integral_value;
}
#ifndef SPLINE_NO_FANCY_INTEGRATION
double AkimaIntegrate(double *x,double *y, int n){
gsl_interp_accel *acc = gsl_interp_accel_alloc (); //Returns pointer to accelerator object, tracks state of lookups
const gsl_interp_type *t = gsl_interp_akima;//Cubic Spline with periodic boundary conditions, result: piecewise cubic on each interval
gsl_spline *spline = gsl_spline_alloc (t,n);//Returns a pointer to a newly allocated interpolation object of type t for n size data-points
gsl_spline_init(spline, x, y, n);
double integral_value;
integral_value = gsl_spline_eval_integ(spline,x[0],x[n-1],acc);//Evaluate Integral
gsl_spline_free (spline);
gsl_interp_accel_free (acc);
return integral_value;
}
double SteffenIntegrate(double *x,double *y, int n){
gsl_interp_accel *acc = gsl_interp_accel_alloc (); //Returns pointer to accelerator object, tracks state of lookups
const gsl_interp_type *t = gsl_interp_steffen;//Cubic Spline with periodic boundary conditions, result: piecewise cubic on each interval
gsl_spline *spline = gsl_spline_alloc (t,n);//Returns a pointer to a newly allocated interpolation object of type t for n size data-points
gsl_spline_init(spline, x, y, n);
double integral_value;
integral_value = gsl_spline_eval_integ(spline,x[0],x[n-1],acc);//Evaluate Integral
gsl_spline_free (spline);
gsl_interp_accel_free (acc);
return integral_value;
}
#endif
}