struct qspline {int n; double* x,y,c};
c and returns the properly filled
qspline structure.
struct qspline* qspline_construct(int n, double* x,double* y);
qspline structure and the
interpolation point z.
double qspline_evaluate(struct qslpine* my_qspline, double z);
qspline_free, which frees
the memory occupied by structure qspline.
void qspline_free(struct qslpine* my_qspline);
class) holds not only data but also all the appropriate
functions (called member functions) which have direct acces to the data
in the structure:
qspline which holds all the
data for spline; the construction function becomes the constructor
method; the evaluation function becomes the member function; the
qspline_free function becomes the destructor method which
is defined automatically (I think):
struct qspline {
vector<double> x,y,c; // the data for the spline
qspline(vector<double> x, vector<double> y); // constructor
double evaluate(double z); // evaluates the interpolation function
};
std::vector<double>
is a useful container in C++.
function<double(double)> construct_qspline_evaluation_function(vector<double> x, vector<double> y);
for(int i = 0; i < 10; i++) { x[i] = i + 0.5 * sin (i); y[i] = i + cos (i * i); }
and plot the two interpolating functions (together with the table
points).
Hints:
graph utility from
plotutils; an example of using it can be found here.
Implement a function which estimates the derivative and the antiderivative (indefinite integral) of a tabulated function by building a quadratic spline and then differentiating and integrating the spline (analytically!).
Check your implementation e.g. on the following data:
for(int i = 0;i<10;i++) { x[i] = i*M_PI/9; y[i] = sin (x[i]); }
Hint: for the integral the routine should return
∫x1z S(x) dx
Implement qubic spline with derivative and antiderivative. Compare with quadratic spline.
For C,C++: check that the GSL cubic spline functions give the same result as your cubic spline.
For C++: make a C++ wrapper for the GSL cubic spline functions and check that they give the same result as your cubic spline.
For other languages with good libraries (Python): check that library implementation of cubic spline gives the same result as your spline.
For other languages without good libraries: check that Octave cubic spline routine gives the same result as your implementation.