Chapter 3: Interpolation and Approximation > spline_2d_value

spline_2d_value

Computes the value of a tensor-product spline or the value of one of its partial derivatives.

Synopsis

#include <imsl.h>

float imsl_f_spline_2d_value (float x, float y, Imsl_f_spline *sp,, 0)

The type double function is imsl_d_spline_2d_value.

Required Arguments

float x   (Input)

float y   (Input)
The (x, y) coordinates of the evaluation point for the tensor-product spline.

Imsl_f_spline *sp   (Input)
Pointer to the structure that represents the spline.

Return Value

The value of a tensor-product spline or one of its derivatives at the point (x, y).

Synopsis with Optional Arguments

#include <imsl.h>

float imsl_f_spline_2d_value (float x, float y, Imsl_f_spline *sp,

IMSL_DERIV, int x_partial, int y_partial,

IMSL_GRID, int nx, float *xvec, int ny, float *yvec, float **value,

IMSL_GRID_USER, int nx, float *xvec, int ny, float *yvec, float value_user[],

0)

Optional Arguments

IMSL_DERIV, int x_partial, int y_partial   (Input)
Let p = x_partial and q = y_partial, and let s be the spline that is represented by the structure *sp, then this option produces the (p, q)-th derivative of s at (x, y), s(p,q) (x, y).
Default: x_partial = y_partial = 0

IMSL_GRID, int nx, float *xvec, int ny, float *yvec, float **value   (Input/Output)
The argument xvec is the array of length nx containing the X coordinates at which the spline is to be evaluated. The argument yvec is the array of length ny containing the Y coordinates at which the spline is to be evaluated. The value of the spline on the nx by ny grid is returned in value.

IMSL_GRID_USER, int nx, float *xvec, int ny, float *yvec, float value_user[]   (Input/Output)
The argument xvec is the array of length nx containing the X coordinates at which the spline is to be evaluated. The argument yvec is the array of length ny containing the Y coordinates at which the spline is to be evaluated. The value of the spline on the nx by ny grid is returned in the user-supplied space value_user.

Description

The function imsl_f_spline_2d_value computes the value of a tensor-product spline or one of its derivatives. This function is based on the discussion in de Boor (1978, pp. 351353).

Examples

Example 1

In this example, a spline interpolant s to a function f is constructed. Using the procedure imsl_f_spline_2d_interp to compute the interpolant, imsl_f_spline_2d_value is employed to compute s(x, y). The values of this partial derivative and the error are computed on a 4 × 4 grid and then displayed.

#include <imsl.h>

#include <stdio.h>

#include <math.h>

 

#define NDATA           11

#define OUTDATA          2

                                /* Define function  */

#define F(x,y)          (float)(x*x*x+y*y)

 

int main()

{

    int                 i, j, num_xdata, num_ydata;

    float               fdata[NDATA][NDATA], xdata[NDATA], ydata[NDATA];

    float               x, y, z;

    Imsl_f_spline       *sp;

                                /* Set up grid  */

    for (i = 0;  i < NDATA;  i++) {

        xdata[i] = ydata[i] = (float) i / ((float) (NDATA - 1));

    }

    for (i = 0;  i < NDATA;  i++) {

        for (j = 0;  j < NDATA;  j++) {

            fdata[i][j] = F(xdata[i], ydata[j]);

        }

    }

    num_xdata = num_ydata = NDATA;

                                /* Compute tensor-product interpolant */

    sp = imsl_f_spline_2d_interp(num_xdata, xdata, num_ydata,

                                                      ydata, fdata, 0);

                                /* Print results */

    printf("     x       y       F(x, y)        Value       Error\n");

    for (i = 0;  i < OUTDATA;  i++) {

        x = (float) (1+i) / (float) (OUTDATA+1);

        for (j = 0;  j < OUTDATA;  j++) {

            y = (float) (1+j) / (float) (OUTDATA+1);

            z = imsl_f_spline_2d_value(x, y, sp, 0);

            printf("  %6.3f  %6.3f  %10.3f   %10.3f   %10.4f\n",

                   x, y, F(x,y), z, fabs(F(x,y)-z));

        }

    }

}

Output

    x       y      F(x, y)       Value        Error

0.333   0.333       0.148        0.148       0.0000

0.333   0.667       0.481        0.481       0.0000

0.667   0.333       0.407        0.407       0.0000

0.667   0.667       0.741        0.741       0.0000

Example 2

In this example, a spline interpolant s to a function f is constructed. Using function imsl_f_spline_2d_interp to compute the interpolant, then imsl_f_spline_2d_value is employed to compute s(2,1) (x, y). The values of this partial derivative and the error are computed on a 4 × 4 grid and then displayed.

#include <imsl.h>

#include <stdio.h>

#include <math.h>

 

#define NDATA           11

#define OUTDATA          2

                                /* Define function  */

#define F(x, y)         (float)(x*x*x*y*y)

#define F21(x,y)        (float)(6.*x*2.*y)

 

int main()

{

    int                 i, j, num_xdata, num_ydata;

    float               fdata[NDATA][NDATA], xdata[NDATA], ydata[NDATA];

    float               x, y, z;

    Imsl_f_spline       *sp;

                                /* Set up grid  */

    for (i = 0;  i < NDATA;  i++) {

        xdata[i] = ydata[i] = (float)i / ((float)(NDATA-1));

    }

    for (i = 0;  i < NDATA;  i++) {

        for (j = 0;  j < NDATA;  j++) {

            fdata[i][j] = F(xdata[i], ydata[j]);

        }

    }

    num_xdata = num_ydata = NDATA;

                                /* Compute tensor-product interpolant */

    sp = imsl_f_spline_2d_interp(num_xdata, xdata, num_ydata,

                                                       ydata, fdata, 0);

                                /* Print results */

    printf("     x       y       F21(x, y)   21InterpDeriv   Error\n");

    for (i = 0;  i < OUTDATA;  i++) {

        x = (float) (1+i) / (float) (OUTDATA+1);

        for (j = 0;  j < OUTDATA;  j++) {

            y = (float) (1+j) / (float) (OUTDATA+1);

            z = imsl_f_spline_2d_value(x, y, sp,

                                       IMSL_DERIV, 2, 1,

                                       0);

            printf("  %6.3f  %6.3f  %10.3f   %10.3f   %10.4f\n",

                   x, y, F21(x, y), z, fabs(F21(x,y)-z));

        }

    }

}

Output

    x       y     F21(x, y)   21InterpDeriv   Error

0.333   0.333       1.333        1.333       0.0000

0.333   0.667       2.667        2.667       0.0000

0.667   0.333       2.667        2.667       0.0000

0.667   0.667       5.333        5.333       0.0001

Warning Errors

IMSL_X_NOT_WITHIN_KNOTS                  The value of x does not lie within the knot sequence.

IMSL_Y_NOT_WITHIN_KNOTS                  The value of y does not lie within the knot sequence.

Fatal Errors

IMSL_KNOT_MULTIPLICITY                     Multiplicity of the knots cannot exceed the order of the spline.

IMSL_KNOT_NOT_INCREASING                The knots must be nondecreasing.


RW_logo.jpg
Contact Support