splineIntegral

Computes the integral of a spline.

Synopsis

splineIntegral (a, b, sp)

Required Arguments

float a (Input)
The lower limit of integration.
float b (Input)
Endpoints for integration.
Imsl_d_spline sp (Input)
The structure that represents the spline.

Return Value

The integral of a spline. If no value can be computed, then NaN is returned.

Description

The function splineIntegral computes the integral of a spline from a to b

\[\int_a^b s(x)dx\]

This routine uses the identity (22) on page 151 of de Boor (1978).

Example

In this example, a cubic spline interpolant to a function f is computed. The values of the integral of this spline are then compared with the exact integral values. Since the default settings are used, the interpolant is determined by the “not-a-knot” condition (see de Boor 1978).

from __future__ import print_function
from numpy import *
from pyimsl.math.splineIntegral import splineIntegral
from pyimsl.math.splineInterp import splineInterp

# Define functions


def F(x):
    return sin(15.0 * x)


def FI(x):
    return (1. - cos(15.0 * x)) / 15.


# Set up a grid
ndata = 21
xdata = empty(ndata)
fdata = empty(ndata)
for i in range(0, ndata):
    xdata[i] = float(i) / (ndata - 1)
    fdata[i] = F(xdata[i])

# Compute cubic spline interpolant
pp = splineInterp(xdata, fdata)

# Print results
print("    x        FI(x)    Interpolant  Integral Error")
for i in range(int(ndata / 2), int(3 * ndata / 2)):
    x = float(i) / (2 * ndata - 2)
    y = splineIntegral(0.0, x, pp)
    print('%6.3f  %10.3f   %10.3f   %10.4f' % (x, FI(x), y, abs(FI(x) - y)))

Output

    x        FI(x)    Interpolant  Integral Error
 0.250       0.121        0.121       0.0001
 0.275       0.104        0.104       0.0001
 0.300       0.081        0.081       0.0001
 0.325       0.056        0.056       0.0001
 0.350       0.033        0.033       0.0001
 0.375       0.014        0.014       0.0002
 0.400       0.003        0.003       0.0002
 0.425       0.000        0.000       0.0002
 0.450       0.007        0.007       0.0002
 0.475       0.022        0.022       0.0001
 0.500       0.044        0.044       0.0001
 0.525       0.068        0.068       0.0001
 0.550       0.092        0.092       0.0001
 0.575       0.113        0.113       0.0001
 0.600       0.127        0.128       0.0001
 0.625       0.133        0.133       0.0001
 0.650       0.130        0.130       0.0001
 0.675       0.118        0.118       0.0001
 0.700       0.098        0.098       0.0001
 0.725       0.075        0.075       0.0001
 0.750       0.050        0.050       0.0001

Warning Errors

IMSL_SPLINE_SMLST_ELEMNT The data arrays xdata and ydata must satisfy \(data_i \leq t_{order-1}\), for i = 1, …, numData.
IMSL_SPLINE_EQUAL_LIMITS The upper and lower endpoints of integration are equal. The indefinite integral is zero.
IMSL_LIMITS_LOWER_TOO_SMALL The left endpoint is less than \(t_{order-1}\). Integration occurs only from \(t_{order-1}\) to b.
IMSL_LIMITS_UPPER_TOO_SMALL The right endpoint is less than \(t_{order-1}\). Integration occurs only from \(t_{order-1}\) to a.
IMSL_LIMITS_UPPER_TOO_BIG The right endpoint is greater than \(t_{splineSpaceDim-1}\). Integration occurs only from a to \(t_{splineSpaceDim-1}\).
IMSL_LIMITS_LOWER_TOO_BIG The left endpoint is greater than \(t_{splineSpaceDim-1}\). Integration occurs only from b to \(t_{splineSpaceDim-1}\).

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.