spline2dValue

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

Synopsis

spline2dValue (x, y, sp)

Required Arguments

float x (Input)

float y (Input)
The (x, y) coordinates of the evaluation point for the tensor-product spline.
Imsl_d_spline sp (Input)
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).

Optional Arguments

deriv, int xPartial, int yPartial (Input)

Let p = xPartial and q = yPartial, 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: xPartial = yPartial = 0

grid, float xvec, float yvec, float value (Input/Output)
The argument xvec is the array containing the X coordinates at which the spline is to be evaluated. The argument yvec is the array 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.

Description

The function spline2dValue 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. 351−353).

Examples

Example 1

In this example, a spline interpolant s to a function f is constructed. Using the procedure spline2dInterp to compute the interpolant, spline2dValue 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.

from __future__ import print_function
from numpy import *
from pyimsl.math.spline2dInterp import spline2dInterp
from pyimsl.math.spline2dValue import spline2dValue

# Define function


def F(x, y):
    return x * x * x + y * y


# Set up grid
ndata = 11
outdata = 2
xdata = empty(ndata)
ydata = empty(ndata)
fdata = empty((ndata, ndata))
for i in range(0, ndata):
    xdata[i] = float(i) / (ndata - 1)
    ydata[i] = float(i) / (ndata - 1)
for i in range(0, ndata):
    for j in range(0, ndata):
        fdata[i, j] = F(xdata[i], ydata[j])

# Compute tensor-product interpolant
sp = spline2dInterp(xdata, ydata, fdata)

# Print results
print("       x       y      F(x, y)       Value        Error")
for i in range(0, outdata):
    x = float(1 + i) / float(outdata + 1)
    for j in range(0, outdata):
        y = float(1 + j) / float(outdata + 1)
        z = spline2dValue(x, y, sp)
        print("  %6.3f  %6.3f  %10.3f   %10.3f   %10.4f"
              % (x, y, F(x, y), z, abs(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 spline2dInterp to compute the interpolant, then spline2dValue 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.

from __future__ import print_function
from numpy import *
from pyimsl.math.spline2dInterp import spline2dInterp
from pyimsl.math.spline2dValue import spline2dValue

# Define functions


def F(x, y):
    return x * x * x * y * y


def F21(x, y):
    return 6. * x * 2. * y


# Set up grid
ndata = 11
outdata = 2
xdata = empty(ndata)
ydata = empty(ndata)
fdata = empty((ndata, ndata))
for i in range(0, ndata):
    xdata[i] = float(i) / (ndata - 1)
    ydata[i] = float(i) / (ndata - 1)
for i in range(0, ndata):
    for j in range(0, ndata):
        fdata[i, j] = F(xdata[i], ydata[j])

# Compute tensor-product interpolant
sp = spline2dInterp(xdata, ydata, fdata)

# Print results
print("       x       y     F21(x, y)   21InterpDeriv   Error")
for i in range(0, outdata):
    x = float(1 + i) / float(outdata + 1)
    for j in range(0, outdata):
        y = float(1 + j) / float(outdata + 1)
        z = spline2dValue(x, y, sp,
                          deriv={'x_partial': 2, 'y_partial': 1})
        print("  %6.3f  %6.3f  %10.3f   %10.3f   %10.4f"
              % (x, y, F21(x, y), z, abs(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.0000

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.