NAME

PDL::Interpolate::Slatec - simple interface to SLATEC interpolation routines

SYNOPSIS

use PDL::Interpolate::Slatec;
use PDL::Math;

# somewhat pointless way to estimate cos and sin,
# but is shows that you can thread if you want to
#
my $x   = pdl( 0 .. 45 ) * 4 * 3.14159 / 180;
my $y   = cat( sin($x), cos($x) );
#
my $obj = new PDL::Interpolate::Slatec( x => $x, y = $y );
#
my $xi  = pdl( 0.5, 1.5, 2.5 );
my $yi  = $obj->interpolate( $xi );
#
print "cos( $xi ) equals ", $yi->slice(':,(0)'), "\n";
cos( [0.5 1.5 2.5] ) equals  [0.87759844 0.070737667 -0.80115622]
#
print "sin( $xi ) equals ", $yi->slice(':,(1)'), "\n";
sin( [0.5 1.5 2.5] ) equals  [ 0.4794191 0.99768655 0.59846449]
#
print cos($xi), "\n", sin($xi), "\n";
[0.87758256 0.070737202 -0.80114362]
[0.47942554 0.99749499 0.59847214]

DESCRIPTION

Use the interface defined by PDL::Interpolate to provide a simple way to use the SLATEC interpolation routines (e.g. see PDL::Slatec). Hence the name for this library - as returned by the library method - is "Slatec".

Currently, only the piecewise cubic Hermite polynomial routines are available (type == "pch").

Attributes

The following changes are made to the attributes of PDL::Interpolate:

Attribute  Flag  Description
bc         sgr   boundary conditions
g          g     estimated gradient at x positions

Attribute  Default    Allowed values
bc         "simple"   see Boundary conditions section
type       "pch"

Given the initial set of points (x,y), the "pch" library estimates the gradient at these points using the given boundary conditions (as specified by the bc attribute). The estimated gradient can be obtained using

$gradient = $obj->get( 'g' );

As described in the "interpolate" method, the "pch" routines can also estimate the gradient, as well as the function value, for a set of $xi.

Boundary conditions for the pch routines

If your data is monotonic, and you are not too bothered about edge effects, then the default value of bc of "simple" is for you. Otherwise, take a look at the description of PDL::Slatec::chic and use a hash reference for the bc attribute, with the following keys:

monotonic

0 if the interpolant is to be monotonic in each interval (so the gradient will be 0 at each switch point), otherwise the gradient is calculated using a 3-point difference formula at switch points. If > 0 then the interpolant is forced to lie close to the data, if < 0 no such control is imposed. Default = 0.

start

A perl list of one or two elements. The first element defines how the boundary condition for the start of the array is to be calculated; it has a range of -5 .. 5, as given for the ic parameter of chic. The second element, only used if options 2, 1, -1, or 2 are chosen, contains the value of the vc parameter. Default = [ 0 ].

end

As for start, but for the end of the data.

An example would be

$obj->set( bc => { start => [ 1, 0 ], end => [ 1, -1 ] }

which sets the first derivative at the first point to 0, and at the last point to -1.

Errors

The status method provides a simple mechanism to check if the previous method was successful. The err attribute contains the $ierr piddle returned by the Slatec routine if a more precise diagnostic is required. To find out which routine was called, use the routine method.

interpolate

my $yi          = $obj->interpolate( $xi );
my ( $yi, $gi ) = $obj->interpolate( $xi );

Returns the interpolated function and derivative at a given set of points.

If evaluated in scalar mode, it returns only the interpolated function values.

integrate

my $ans = $obj->integrate( index => pdl( 2, 5 ) );
my $ans = $obj->integrate( x => pdl( 2.3, 4.5 ) );

Integrate the function stored in the PDL::Interpolate::Slatec object.

The integration can either be between points of the original x array (index), or arbitrary x values (x). For both cases, a two element piddle should be given, to specify the start and end points of the integration.

index

The values given refer to the indices of the points in the x array.

x

The array contains the actual values to integrate between.

If the status method returns a value of -1, then one or both of the integration limits did not lie inside the x array. Caveat emptor with the result in such a case.

The reason for using piddles, rather than arrays, is that it allows for threading.

AUTHOR

Copyright (C) 2000 Doug Burke (burke@ifa.hawaii.edu). All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation as described in the file COPYING in the PDL distribution.

SEE ALSO

PDL::Interpolate, PDL, perltoot(1).