Qwt Programmer's Reference

QwtSpline


NAME

QwtSpline - A class for spline interpolation

SYNOPSIS

#include<qwt_spline.h>

PUBLIC MEMBERS

QwtSpline
Constructor
~QwtSpline
Destructor
value
Return interpolated value
recalc
Build the spline
copyValues
Set policy: copy or attach arrays

DESCRIPTION

The QwtSpline class is used for cubical spline interpolation. Two types of splines, natural and periodic, are supported.

Usage:

  1. First call recalc to determine the spline coefficients for a tabulated function y(x).
  2. After the coefficients have been set up, the interpolated function value for an argument x can be determined by calling value.

In order to save storage space, QwtSpline can be advised not to buffer the contents of x and y. This means that the arrays have to remain valid and unchanged for the interpolation to work properly. This can be achieved by calling copyValues.

EXAMPLE


      #include<qwt_spline.h>
      #include<iostream.h>

      QwtSpline s;
      double x[30], y[30], xInter[300], yInter[300];
      int i;

      for(i=0;i<30;i++)               // fill up x[] and y[]
          cin >> x[i] >> y[i];

      if (s.recalc(x,y,30,0) == 0)    // build natural spline
      {
          for(i=0;i<300;i++)          // interpolate
          {
              xInter[i] = x[0] + double(i) * (x[29] - x[0]) / 299.0;
              yInter[i] = s.value( xInter[i] );
          }

          do_something(xInter, yInter, 300);
      }
      else
          cerr << "Uhhh...\n";


MEMBER FUNCTION DESCRIPTION


QwtSpline::value

Calculate the interpolated function value corresponding to a given argument x.

Syntax

double QwtSpline::value(double x) const

QwtSpline::QwtSpline

Construct a QwtSpline instance

Syntax

QwtSpline::QwtSpline()

QwtSpline::copyValues

Advise recalc() to buffer the tabulated function or switch off internal buffering

Syntax

void QwtSpline::copyValues()

Parameters

int tf
if nonzero, the function table will be buffered

Description

By default, QwtSpline maintains an internal copy of the tabulated function given as *x and *y arguments of recalc(). If copyValues() is called with zero argument, subsequent calls to recalc() will not buffer these values anymore and just store the pointers instead. The value() function will then silently assume that these pointers remained valid and that the contents of the arrays have not been changed since the last recalc(). If called with no or nonzero argument, any following recalc() calls will use the internal buffer.

Note

copyValues() resets all the contents of QwtSpline. A subsequent recalc() will be necessary.

QwtSpline::~QwtSpline

Destroy a QwtSpline instance

Syntax

QwtSpline::~QwtSpline()

QwtSpline::recalc

re-calculate the spline coefficients

Parameters

double *x, double *y
points
int n
number of points
int periodic
if non-zero, calculate periodic spline

Return Type

int

Return Value

0
successful
Qwt::ErrMono
Sequence of x values is not strictly monotone increasing
Qwt::ErrNoMem
Couldn't allocate memory

Description

Depending on the value of <periodic>, this function will determine the coefficients for a natural or a periodic spline and store them internally. By default, it also buffers the values of x and y, which are needed for the interpolation (See value()). In order to save memory, this last behaviour may be changed with the copyValues() function.

Note

The sequence of x (but not y) values has to be strictly monotone increasing, which means
x[0] < x[1] < .... < x[n-1].
If this is not the case, the function will return an error.

Syntax

void QwtSpline::recalc(double *x, double *y, int n)

QwtSpline::buildNatSpline

Determines the coefficients for a natural spline

Return Type

void

Return Value

0
successful
Qwt::ErrMono
Sequence of x values is not strictly monotone increasing
Qwt::ErrNoMem
Couldn't allocate memory

Description

Syntax

void QwtSpline::buildNatSpline()

QwtSpline::buildPerSpline

Determines the coefficients for a periodic spline

Return Type

int

Return Values

0
successful
Qwt::ErrMono
Sequence of x values is not strictly monotone increasing
Qwt::ErrNoMem
Couldn't allocate memory

Description

Syntax

void QwtSpline::buildPerSpline()
Qwt Widget Library 02/04/98