cubSplineIntegral

Computes the integral of a cubic spline.

Synopsis

cubSplineIntegral (a, b, ppoly)

The type double function is cubSplineIntegral.

Required Arguments

float a (Input)

float b (Input)
Endpoints for integration.
Imsl_d_ppoly ppoly (Input)
Pointer to the piecewise polynomial structure that represents the cubic spline.

Return Value

The integral from a to b of the cubic spline. If no value can be computed, then NaN is returned.

Description

The function cubSplineIntegral computes the integral of a cubic spline from a to b.

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

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.cubSplineInterpECnd import cubSplineInterpECnd
from pyimsl.math.cubSplineIntegral import cubSplineIntegral

# Define function


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

# Integral from 0 to 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 = cubSplineInterpECnd(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 = cubSplineIntegral(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