PDL::Slatec
Slatec(c)      User Contributed Perl Documentation      Slatec(c)



NAME
       PDL::Slatec - PDL interface to the slatec numerical pro-
       gramming library

SYNOPSIS
        use PDL::Slatec;

        ($ndeg, $r, $ierr, $a) = polyfit($x, $y, $w, $maxdeg, $eps);


DESCRIPTION
       This module serves the dual purpose of providing an inter-
       face to parts of the slatec library and showing how to
       interface PDL to an external library.  Using this library
       requires a fortran compiler; the source for the routines
       is provided for convenience.

       Currently available are routines to: manipulate matrices;
       calculate FFT's; fit data using polynomials; and interpo-
       late/integrate data using piecewise cubic Hermite interpo-
       lation.

       Piecewise cubic Hermite interpolation (PCHIP)

       PCHIP is the slatec package of routines to perform piece-
       wise cubic Hermite interpolation of data.  It features
       software to produce a monotone and "visually pleasing"
       interpolant to monotone data.  According to Fritsch &
       Carlson ("Monotone piecewise cubic interpolation", SIAM
       Journal on Numerical Analysis 17, 2 (April 1980), pp.
       238-246), such an interpolant may be more reasonable than
       a cubic spline if the data contains both "steep" and
       "flat" sections.  Interpolation of cumulative probability
       distribution functions is another application.  These rou-
       tines are cryptically named (blame FORTRAN), beginning
       with 'ch', and accept either float or double piddles.

       Most of the routines require an integer parameter called
       "check"; if set to 0, then no checks on the validity of
       the input data are made, otherwise these checks are made.
       The value of "check" can be set to 0 if a routine such as
       chim has already been successfully called.

       o   If not known, estimate derivative values for the
           points using the chim, chic, or chsp routines (the
           following routines require both the function ("f") and
           derivative ("d") values at a set of points ("x")).

       o   Evaluate, integrate, or differentiate the resulting
           PCH function using the routines: chfd; chfe; chia;
           chid.

       o   If desired, you can check the monotonicity of your
           data using chcm.

FUNCTIONS
       eigsys

       Eigenvalues and eigenvectors of a real positive definite
       symmetric matrix.

        ($eigvals,$eigvecs) = eigsys($mat)

       Note: this function should be extended to calculate only
       eigenvalues if called in scalar context!

       matinv

       Inverse of a square matrix

        ($inv) = matinv($mat)


       polyfit

       Convenience wrapper routine about the "polfit" "slatec"
       function.  Separates supplied arguments and return values.

       Fit discrete data in a least squares sense by polynomials
       in one variable.

        ($ndeg, $r, $ierr, $a) = polyfit($x, $y, $w, $maxdeg, $eps);

       "eps" is modified to contain the rms error of the fit.

       polycoef

       Convenience wrapper routine around the "pcoef" "slatec"
       function.  Separates supplied arguments and return values.

       Convert the "polyfit"/"polfit" coefficients to Taylor
       series form.

        $tc = polycoef($l, $c, $a);


       polyvalue

       Convenience wrapper routine around the "pvalue" "slatec"
       function.  Separates supplied arguments and return values.

       For multiple input x positions, a corresponding y position
       is calculated.

       The derivatives PDL is one dimensional (of size "nder") if
       a single x position is supplied, two dimensional if more
       than one x position is supplied.

       Use the coefficients generated by "polyfit" (or "polfit")
       to evaluate the polynomial fit of degree "l", along with
       the first "nder" of its derivatives, at a specified point.

        ($yfit, $yp) = polyvalue($l, $nder, $x, $a);


       det

       compute the determinant of an invertible matrix

         $mat = zeroes(5,5); $mat->diagonal(0,1) .= 1; # unity matrix
         $det = det $mat;

       Usage:

         $determinant = det $matrix;

         Signature: det(mat(n,m); [o] det())

       "det" computes the determinant of an invertible matrix and
       barfs if the matrix argument provided is non-invertible.
       The matrix threads as usual.

       svdc

         Signature: (x(n,p);[o]s(s);[o]e(e);[o]u(n,p);[o]v(p,p);[o]work(k);int job();int [o]info())

       singular value decomposition of a matrix

       poco

         Signature: (a(n,n);rcond();[o]z(z);int [o]info())

       Factor a real symmetric positive definite matrix and esti-
       mate the condition number of the matrix.

       geco

         Signature: (a(n,n);int [o]ipvt(t);[o]rcond();[o]z(z))

       Factor a matrix using Gaussian elimination and estimate
       the condition number of the matrix.

       gefa

         Signature: (a(n,n);int [o]ipvt(t);int [o]info())

       Factor a matrix using Gaussian elimination.

       podi

         Signature: (a(n,n);[o]det(two=2);int job())

       Compute the determinant and inverse of a certain real sym-
       metric positive definite matrix using the factors computed
       by poco.

       gedi

         Signature: (a(n,n);int [o]ipvt(t);[o]det(two=2);[o]work(k);int job())

       Compute the determinant and inverse of a matrix using the
       factors computed by geco or gefa.

       gesl

         Signature: (a(lda,n);int ipvt(t);b(b);int job())

       Solve the real system "A*X=B" or "TRANS(S)*X=B" using the
       factors computed by geco or gefa.

       rs

         Signature: (a(n,n);[o]w(w);int matz();[o]z(n,n);[t]fvone(e);[t]fvtwo(o);int [o]ierr())

       This subroutine calls the recommended sequence of subrou-
       tines from the eigensystem subroutine package (EISPACK) to
       find the eigenvalues and eigenvectors (if desired) of a
       REAL SYMMETRIC matrix.

       ezffti

         Signature: (int n();[o]wsave(e))

       Subroutine ezffti initializes the work array "wsave()"
       which is used in both ezfftf and ezfftb.  The prime fac-
       torization of "n" together with a tabulation of the
       trigonometric functions are computed and stored in
       "wsave()".

       ezfftf

         Signature: (r(r);[o]azero();[o]a(a);[o]b(b);wsave(e))


       ezfftb

         Signature: ([o]r(r);azero();a(a);b(b);wsave(e))


       polfit

         Signature: (x(x);y(y);w(w);int maxdeg();int [o]ndeg();[o]eps();[o]r(r);int [o]ierr();[o]a(a))

       Fit discrete data in a least squares sense by polynomials
       in one variable. "x()", "y()" and "w()" must be of the
       same type.

       pcoef

         Signature: (int l();c();[o]tc(c);a(a))

       Convert the "polfit" coefficients to Taylor series form.
       "c" and "a()" must be of the same type.

       pvalue

         Signature: (int l();x();[o]yfit();[o]yp(p);a(a))

       Use the coefficients generated by "polfit" to evaluate the
       polynomial fit of degree "l", along with the first "nder"
       of its derivatives, at a specified point. "x" and "a" must
       be of the same type.

       chim

         Signature: (x(x);f(f);[o]d(d);int [o]ierr())

       Calculate the derivatives of (x,f(f)) using cubic Hermite
       interpolation.

       Calculate the derivatives at the given set of points
       ("$x,$f", where $x is strictly increasing).  The resulting
       set of points - "$x,$f,$d", referred to as the cubic Her-
       mite representation - can then be used in other functions,
       such as chfe, chfd, and chia.

       The boundary conditions are compatible with monotonicity,
       and if the data are only piecewise monotonic, the inter-
       polant will have an extremum at the switch points; for
       more control over these issues use chic.

       Error status returned by $ierr:

       o   0 if successful.

       o   > 0 if there were "ierr" switches in the direction of
           monotonicity (data still valid).

       o   -1 if "nelem($x) < 2".

       o   -3 if $x is not strictly increasing.

       chic

         Signature: (int ic(two=2);vc(two=2);mflag();x(x);f(f);[o]d(d);wk(k);int [o]ierr())

       Calculate the derivatives of (x,f(f)) using cubic Hermite
       interpolation.

       Calculate the derivatives at the given points ("$x,$f",
       where $x is strictly increasing).  Control over the bound-
       ary conditions is given by the $ic and $vc piddles, and
       the value of $mflag determines the treatment of points
       where monotoncity switches direction. A simpler, more
       restricted, interface is available using chim.

       The first and second elements of $ic determine the bound-
       ary conditions at the start and end of the data respec-
       tively.  If the value is 0, then the default condition, as
       used by chim, is adopted.  If greater than zero, no
       adjustment for monotonicity is made, otherwise if less
       than zero the derivative will be adjusted.  The allowed
       magnitudes for ic(c) are:

       o   1 if first derivative at x(x) is given in vc(c).

       o   2 if second derivative at x(x) is given in vc(c).

       o   3 to use the 3-point difference formula for d(d).
           (Reverts to the default b.c. if "n < 3")

       o   4 to use the 4-point difference formula for d(d).
           (Reverts to the default b.c. if "n < 4")

       o   5 to set d(d) so that the second derivative is contin-
           uous at x(x).  (Reverts to the default b.c. if "n <
           4")

       The values for ic(c) are the same as above, except that
       the first-derivative value is stored in vc(c) for cases 1
       and 2.  The values of $vc need only be set if options 1 or
       2 are chosen for $ic.

       Set "$mflag = 0" if interpolant is required to be mono-
       tonic in each interval, regardless of the data. This
       causes $d to be set to 0 at all switch points. Set $mflag
       to be non-zero to use a formula based on the 3-point dif-
       ference formula at switch points. If "$mflag > 0", then
       the interpolant at swich points is forced to not deviate
       from the data by more than "$mflag*dfloc", where "dfloc"
       is the maximum of the change of $f on this interval and
       its two immediate neighbours.  If "$mflag < 0", no such
       control is to be imposed.

       The piddle $wk is only needed for work space. However, I
       could not get it to work as a temporary variable, so you
       must supply it; it is a 1D piddle with "2*n" elements.

       Error status returned by $ierr:

       o   0 if successful.

       o   1 if "ic(c) < 0" and d(d) had to be adjusted for mono-
           tonicity.

       o   2 if "ic(c) < 0" and "d(n-1)" had to be adjusted for
           monotonicity.

       o   3 if both 1 and 2 are true.

       o   -1 if "n < 2".

       o   -3 if $x is not strictly increasing.

       o   -4 if "abs(ic(c)) > 5".

       o   -5 if "abs(ic(c)) > 5".

       o   -6 if both -4 and -5  are true.

       o   -7 if "nwk < 2*(n-1)".

       chsp

         Signature: (int ic(two=2);vc(two=2);x(x);f(f);[o]d(d);wk(k);int [o]ierr())

       Calculate the derivatives of (x,f(f)) using cubic spline
       interpolation.

       Calculate the derivatives, using cubic spline interpola-
       tion, at the given points ("$x,$f"), with the specified
       boundary conditions.  Control over the boundary conditions
       is given by the $ic and $vc piddles.  The resulting values
       - "$x,$f,$d" - can be used in all the functions which
       expect a cubic Hermite function.

       The first and second elements of $ic determine the bound-
       ary conditions at the start and end of the data respec-
       tively.  The allowed values for ic(c) are:

       o   0 to set d(d) so that the third derivative is continu-
           ous at x(x).

       o   1 if first derivative at x(x) is given in "vc(0").

       o   2 if second derivative at "x(0") is given in vc(c).

       o   3 to use the 3-point difference formula for d(d).
           (Reverts to the default b.c. if "n < 3".)

       o   4 to use the 4-point difference formula for d(d).
           (Reverts to the default b.c. if "n < 4".)

       The values for ic(c) are the same as above, except that
       the first-derivative value is stored in vc(c) for cases 1
       and 2.  The values of $vc need only be set if options 1 or
       2 are chosen for $ic.

       The piddle $wk is only needed for work space. However, I
       could not get it to work as a temporary variable, so you
       must supply it; it is a 1D piddle with "2*n" elements.

       Error status returned by $ierr:

       o   0 if successful.

       o   -1  if "nelem($x) < 2".

       o   -3  if $x is not strictly increasing.

       o   -4  if "ic(c) < 0" or "ic(c) > 4".

       o   -5  if "ic(c) < 0" or "ic(c) > 4".

       o   -6  if both of the above are true.

       o   -7  if "nwk < 2*n".

       o   -8  in case of trouble solving the linear system for
           the interior derivative values.

       chfd

         Signature: (x(x);f(f);d(d);int check();xe(e);[o]fe(e);[o]de(e);int [o]ierr())

       Interpolate function and derivative values.

       Given a piecewise cubic Hermite function - such as from
       chim - evaluate the function ($fe) and derivative ($de) at
       a set of points ($xe).  If function values alone are
       required, use chfe.  Set "check" to 0 to skip checks on
       the input data.

       Error status returned by $ierr:

       o   0 if successful.

       o   >0 if extrapolation was performed at "ierr" points
           (data still valid).

       o   -1 if "nelem($x) < 2"

       o   -3 if $x is not strictly increasing.

       o   -4 if "nelem($xe) < 1".

       o   -5 if an error has occurred in a lower-level routine,
           which should never happen.

       chfe

         Signature: (x(x);f(f);d(d);int check();xe(e);[o]fe(e);int [o]ierr())

       Interpolate function values.

       Given a piecewise cubic Hermite function - such as from
       chim - evaluate the function ($fe) at a set of points
       ($xe).  If derivative values are also required, use chfd.
       Set "check" to 0 to skip checks on the input data.

       Error status returned by $ierr:

       o   0 if successful.

       o   >0 if extrapolation was performed at "ierr" points
           (data still valid).

       o   -1 if "nelem($x) < 2"

       o   -3 if $x is not strictly increasing.

       o   -4 if "nelem($xe) < 1".

       chia

         Signature: (x(x);f(f);d(d);int check();a();b();[o]ans();int [o]ierr())

       Integrate (x,f(f)) over arbitrary limits.

       Evaluate the definite integral of a a piecewise cubic Her-
       mite function over an arbitrary interval, given by
       "[$a,$b]".  See chid if the integration limits are data
       points.  Set "check" to 0 to skip checks on the input
       data.

       The values of $a and $b do not have to lie within $x,
       although the resulting integral value will be highly sus-
       pect if they are not.

       Error status returned by $ierr:

       o   0 if successful.

       o   1 if $a lies outside $x.

       o   2 if $b lies outside $x.

       o   3 if both 1 and 2 are true.

       o   -1 if "nelem($x) < 2"

       o   -3 if $x is not strictly increasing.

       o   -4 if an error has occurred in a lower-level routine,
           which should never happen.

       chid

         Signature: (x(x);f(f);d(d);int check();int ia();int ib();[o]ans();int [o]ierr())

       Integrate (x,f(f)) between data points.

       Evaluate the definite integral of a a piecewise cubic Her-
       mite function between "x($ia)" and "x($ib)".

       See chia for integration between arbitrary limits.

       Although using a fortran routine, the values of $ia and
       $ib are zero offset.  Set "check" to 0 to skip checks on
       the input data.

       Error status returned by $ierr:

       o   0 if successful.

       o   -1 if "nelem($x) < 2".

       o   -3 if $x is not strictly increasing.

       o   -4 if $ia or $ib is out of range.

       chcm

         Signature: (x(x);f(f);d(d);int check();int [o]ismon(n);int [o]ierr())

       Check the given piecewise cubic Hermite function for mono-
       tonicity.

       The outout piddle $ismon indicates over which intervals
       the function is monotonic.  Set "check" to 0 to skip
       checks on the input data.

       For the data interval "[x(x),x(i+1)]", the values of
       ismon(n) can be:

       o   -3 if function is probably decreasing

       o   -1 if function is strictly decreasing

       o   0  if function is constant

       o   1  if function is strictly increasing

       o   2  if function is non-monotonic

       o   3  if function is probably increasing

       If "abs(ismon(n)) == 3", the derivative values are near
       the boundary of the monotonicity region. A small increase
       produces non-monotonicity, whereas a decrease produces
       strict monotonicity.

       The above applies to "i = 0 .. nelem($x)-1". The last ele-
       ment of $ismon indicates whether the entire function is
       monotonic over $x.

       Error status returned by $ierr:

       o   0 if successful.

       o   -1 if "n < 2".

       o   -3 if $x is not strictly increasing.

AUTHOR
       Copyright (C) 1997 Tuomas J. Lukka.  Copyright (C) 2000
       Tim Jenness, Doug Burke.  All rights reserved. There is no
       warranty. You are allowed to redistribute this software /
       documentation under certain conditions. For details, see
       the file COPYING in the PDL distribution. If this file is
       separated from the PDL distribution, the copyright notice
       should be included in the file.



perl v5.6.1                 2002-04-08                  Slatec(c)