NAG Library Routine Document
C06LAF
1 Purpose
C06LAF estimates values of the inverse Laplace transform of a given function using a Fourier series approximation. Real and imaginary parts of the function, and a bound on the exponential order of the inverse, are required.
2 Specification
SUBROUTINE C06LAF ( 
FUN, N, T, VALINV, ERREST, RELERR, ALPHAB, TFAC, MXTERM, NTERMS, NA, ALOW, AHIGH, NFEVAL, WORK, IFAIL) 
INTEGER 
N, MXTERM, NTERMS, NA, NFEVAL, IFAIL 
REAL (KIND=nag_wp) 
T(N), VALINV(N), ERREST(N), RELERR, ALPHAB, TFAC, ALOW, AHIGH, WORK(4*MXTERM+2) 
EXTERNAL 
FUN 

3 Description
Given a function
$F\left(p\right)$ defined for complex values of
$p$, C06LAF estimates values of its inverse Laplace transform by Crump's method (see
Crump (1976)). (For a definition of the Laplace transform and its inverse, see the
C06 Chapter Introduction.)
Crump's method applies the epsilon algorithm (see
Wynn (1956)) to the summation in Durbin's Fourier series approximation (see
Durbin (1974))
for
$j=1,2,\dots ,n$, by choosing
$a$ such that a prescribed relative error should be achieved. The method is modified slightly if
$t=0.0$ so that an estimate of
$f\left(0.0\right)$ can be obtained when it has a finite value.
$\tau $ is calculated as
${t}_{\mathrm{fac}}\times \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(0.01,{t}_{j}\right)$, where
${t}_{\mathrm{fac}}>0.5$. You specify
${t}_{\mathrm{fac}}$ and
${\alpha}_{b}$, an upper bound on the exponential order
$\alpha $ of the inverse function
$f\left(t\right)$.
$\alpha $ has two alternative interpretations:
(i) 
$\alpha $ is the smallest number such that
for large $t$, 
(ii) 
$\alpha $ is the real part of the singularity of $F\left(p\right)$ with largest real part. 
The method depends critically on the value of
$\alpha $. See
Section 8 for further details. The routine calculates at least two different values of the parameter
$a$, such that
$a>{\alpha}_{b}$, in an attempt to achieve the requested relative error and provide error estimates. The values of
${t}_{\mathit{j}}$, for
$\mathit{j}=1,2,\dots ,n$, must be supplied in monotonically increasing order. The routine calculates the values of the inverse function
$f\left({t}_{j}\right)$ in decreasing order of
$j$.
4 References
Crump K S (1976) Numerical inversion of Laplace transforms using a Fourier series approximation J. Assoc. Comput. Mach. 23 89–96
Durbin F (1974) Numerical inversion of Laplace transforms: An efficient improvement to Dubner and Abate's method Comput. J. 17 371–376
Wynn P (1956) On a device for computing the ${e}_{m}\left({S}_{n}\right)$ transformation Math. Tables Aids Comput. 10 91–96
5 Parameters
 1: FUN – SUBROUTINE, supplied by the user.External Procedure
FUN must evaluate the real and imaginary parts of the function
$F\left(p\right)$ for a given value of
$p$.
The specification of
FUN is:
REAL (KIND=nag_wp) 
PR, PI, FR, FI 

 1: PR – REAL (KIND=nag_wp)Input
 2: PI – REAL (KIND=nag_wp)Input
On entry: the real and imaginary parts of the argument $p$.
 3: FR – REAL (KIND=nag_wp)Output
 4: FI – REAL (KIND=nag_wp)Output
On exit: the real and imaginary parts of the value $F\left(p\right)$.
FUN must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which C06LAF is called. Parameters denoted as
Input must
not be changed by this procedure.
 2: N – INTEGERInput
On entry: $n$, the number of points at which the value of the inverse Laplace transform is required.
Constraint:
${\mathbf{N}}\ge 1$.
 3: T(N) – REAL (KIND=nag_wp) arrayInput
On entry: each ${\mathbf{T}}\left(\mathit{j}\right)$ must specify a point at which the inverse Laplace transform is required , for $\mathit{j}=1,2,\dots ,n$.
Constraint:
$0.0\le {\mathbf{T}}\left(1\right)<{\mathbf{T}}\left(2\right)<\cdots <{\mathbf{T}}\left(n\right)$.
 4: VALINV(N) – REAL (KIND=nag_wp) arrayOutput
On exit: an estimate of the value of the inverse Laplace transform at
$t={\mathbf{T}}\left(\mathit{j}\right)$, for $\mathit{j}=1,2,\dots ,n$.
 5: ERREST(N) – REAL (KIND=nag_wp) arrayOutput
On exit: an estimate of the error in
${\mathbf{VALINV}}\left(j\right)$. This is usually an estimate of relative error but, if
${\mathbf{VALINV}}\left(j\right)<{\mathbf{RELERR}}$,
${\mathbf{ERREST}}\left(j\right)$ estimates the absolute error.
${\mathbf{ERREST}}\left(j\right)$ is unreliable when
${\mathbf{VALINV}}\left(j\right)$ is small but slightly greater than
RELERR.
 6: RELERR – REAL (KIND=nag_wp)Input
On entry: the required relative error in the values of the inverse Laplace transform. If the absolute value of the inverse is less than
RELERR, then absolute accuracy is used instead.
RELERR must be in the range
$0.0\le {\mathbf{RELERR}}<1.0$. If
RELERR is set too small or to
$0.0$, then the routine uses a value sufficiently larger than
machine precision.
 7: ALPHAB – REAL (KIND=nag_wp)Input
On entry:
${\alpha}_{b}$, an upper bound for
$\alpha $ (see
Section 3). Usually,
${\alpha}_{b}$ should be specified equal to, or slightly larger than, the value of
$\alpha $. If
${\alpha}_{b}<\alpha $ then the prescribed accuracy may not be achieved or completely incorrect results may be obtained. If
${\alpha}_{b}$ is too large C06LAF will be inefficient and convergence may not be achieved.
Note: it is as important to specify ${\alpha}_{b}$ correctly as it is to specify the correct function for inversion.
 8: TFAC – REAL (KIND=nag_wp)Input
On entry:
${t}_{\mathrm{fac}}$, a factor to be used in calculating the parameter
$\tau $. Larger values (e.g.,
$5.0$) may be specified for difficult problems, but these may require very large values of
MXTERM.
Suggested value:
${\mathbf{TFAC}}=0.8$.
Constraint:
${\mathbf{TFAC}}>0.5$.
 9: MXTERM – INTEGERInput
On entry: the maximum number of (complex) terms to be used in the evaluation of the Fourier series.
Suggested value:
${\mathbf{MXTERM}}\ge 100$, except for very simple problems.
Constraint:
${\mathbf{MXTERM}}\ge 1$.
 10: NTERMS – INTEGEROutput
On exit: the number of (complex) terms actually used.
 11: NA – INTEGEROutput
On exit: the number of values of
$a$ used by the routine. See
Section 8.
 12: ALOW – REAL (KIND=nag_wp)Output
On exit: the smallest value of
$a$ used in the algorithm. This may be used for checking the value of
${\mathbf{ALPHAB}}$ see
Section 8.
 13: AHIGH – REAL (KIND=nag_wp)Output
On exit: the largest value of
$a$ used in the algorithm. This may be used for checking the value of
${\mathbf{ALPHAB}}$ see
Section 8.
 14: NFEVAL – INTEGEROutput
On exit: the number of calls to
FUN made by the routine.
 15: WORK($4\times {\mathbf{MXTERM}}+2$) – REAL (KIND=nag_wp) arrayWorkspace
 16: IFAIL – INTEGERInput/Output

On entry:
IFAIL must be set to
$0$,
$1\text{ or}1$. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
$1\text{ or}1$ is recommended. If the output of error messages is undesirable, then the value
$1$ is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if
${\mathbf{IFAIL}}\ne {\mathbf{0}}$ on exit, the recommended value is
$1$.
When the value $\mathbf{1}\text{ or}1$ is used it is essential to test the value of IFAIL on exit.
On exit:
${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${{\mathbf{1}}}$, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Note: C06LAF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
 ${\mathbf{IFAIL}}=1$
On entry,  ${\mathbf{N}}<1$, 
or  ${\mathbf{MXTERM}}<1$, 
or  ${\mathbf{RELERR}}<0.0$, 
or  ${\mathbf{RELERR}}\ge 1.0$, 
or  ${\mathbf{TFAC}}\le 0.5$. 
 ${\mathbf{IFAIL}}=2$
On entry,  ${\mathbf{T}}\left(1\right)<0.0$, 
or  ${\mathbf{T}}\left(1\right),{\mathbf{T}}\left(2\right),\dots ,{\mathbf{T}}\left({\mathbf{N}}\right)$ are not in strictly increasing order. 
 ${\mathbf{IFAIL}}=3$
${\mathbf{T}}\left({\mathbf{N}}\right)$ is too large for this value of
ALPHAB. If necessary, scale the problem as described in
Section 8.
 ${\mathbf{IFAIL}}=4$
The required accuracy cannot be obtained. It is possible that
ALPHAB is less than
$\alpha $. Alternatively, the problem may be especially difficult. Try increasing
TFAC,
ALPHAB or both.
 ${\mathbf{IFAIL}}=5$
Convergence failure in the epsilon algorithm. Some values of
${\mathbf{VALINV}}\left(j\right)$ may be calculated to the desired accuracy; this may be determined by examining the values of
${\mathbf{ERREST}}\left(j\right)$. Try reducing the range of
T or increasing
MXTERM. If
${\mathbf{IFAIL}}={\mathbf{5}}$ still results, try reducing
TFAC.
 ${\mathbf{IFAIL}}=6$
All values of
${\mathbf{VALINV}}\left(j\right)$ have been calculated but not all are to the requested accuracy; the values of
${\mathbf{ERREST}}\left(j\right)$ should be examined carefully. Try reducing the range of
$t$, or increasing
TFAC,
ALPHAB or both.
7 Accuracy
The error estimates are often very close to the true error but, because the error control depends on an asymptotic formula, the required error may not always be met. There are two principal causes of this: Gibbs' phenomena, and zero or small values of the inverse Laplace transform.
Gibbs' phenomena (see the
C06 Chapter Introduction) are exhibited near
$t=0.0$ (due to the method) and around discontinuities in the inverse Laplace transform
$f\left(t\right)$. If there is a discontinuity at
$t=c$ then the method converges such that
$f\left(c\right)\to \left(f\left(c\right)+f\left(c+\right)\right)/2$.
Apparent loss of accuracy, when
$f\left(t\right)$ is small, may not be serious. Crump's method keeps control of relative error so that good approximations to small function values may appear to be very inaccurate. If
$\leftf\left(t\right)\right$ is estimated to be less than
RELERR then this routine switches to absolute error estimation. However, when
$\leftf\left(t\right)\right$ is slightly larger than
RELERR the relative error estimates are likely to cause
${\mathbf{IFAIL}}={\mathbf{6}}$. If this is found inconvenient it can sometimes be avoided by adding
$k/p$ to the function
$F\left(p\right)$, which shifts the inverse to
$k+f\left(t\right)$.
Loss of accuracy may also occur for highly oscillatory functions.
More serious loss of accuracy can occur if
$\alpha $ is unknown and is incorrectly estimated. See
Section 8.
The value of
$n$ is less important in general than the value of
NTERMS. Unless
FUN is very inexpensive to compute, the timing is proportional to
${\mathbf{NA}}\times {\mathbf{NTERMS}}$. For simple problems
${\mathbf{NA}}=2$ but in difficult problems
NA may be somewhat larger.
You are referred to the
C06 Chapter Introduction for advice on simplifying problems with particular difficulties, e.g., where the inverse is known to be a step function.
The method does not work well for large values of
$t$ when
$\alpha $ is positive. It is advisable, especially if
${\mathbf{IFAIL}}={\mathbf{3}}$ is obtained, to scale the problem if
$\left\alpha \right$ is much greater than
$1.0$. See the
C06 Chapter Introduction.
The range of values of $t$ specified for a particular call should not be greater than about $10$ units. This is because the method uses parameters based on the value ${\mathbf{T}}\left(n\right)$ and these tend to be less appropriate as $t$ becomes smaller. However, as the timing of the routine is not especially dependent on $n$, it is usually far more efficient to evaluate the inverse for ranges of $t$ than to make separate calls to the routine for each value of $t$.
The most important parameter to specify correctly is
ALPHAB, an upper bound for
$\alpha $. If, on entry,
ALPHAB is sufficiently smaller than
$\alpha $ then completely incorrect results will be obtained with
${\mathbf{IFAIL}}={\mathbf{0}}$. Unless
$\alpha $ is known theoretically it is strongly advised that you should test any estimated value used. This may be done by specifying a single value of
$t$ (i.e
${\mathbf{T}}\left(n\right)$,
$n=1$) with two sets of suitable values of
TFAC,
RELERR and
MXTERM, and examining the resulting values of
ALOW and
AHIGH. The value of
${\mathbf{T}}\left(1\right)$ should be chosen very carefully and the following points should be borne in mind:
(i) 
${\mathbf{T}}\left(1\right)$ should be small but not too close to $0.0$ because of Gibbs' phenomenon (see Section 7), 
(ii) 
the larger the value of ${\mathbf{T}}\left(1\right)$, the smaller the range of values of $a$ that will be used in the algorithm, 
(iii) 
${\mathbf{T}}\left(1\right)$ should ideally not be chosen such that $f\left({\mathbf{T}}\left(1\right)\right)=0.0$ or a very small value. For suitable problems ${\mathbf{T}}\left(1\right)$ might be chosen as, say, $0.1$ or $1.0$ depending on these factors. The routine calculates ALOW from the formula

Additional values of
$a$ are computed by adding
$1/\tau $ to the previous value. As
$\tau ={\mathbf{TFAC}}\times {\mathbf{T}}\left(n\right)$, it will be seen that large values of
TFAC and
RELERR will test for
$a$ close to
ALPHAB. Small values of
TFAC and
RELERR will test for
$a$ large. If the result of both tests is
${\mathbf{IFAIL}}={\mathbf{0}}$, with comparable values for the inverse, then this gives some credibility to the chosen value of
ALPHAB. You should note that this test could be more computationally expensive than the calculation of the inverse itself. The example program (see
Section 9) illustrates how such a test may be performed.
9 Example
This example estimates the inverse Laplace transform of the function
$F\left(p\right)=1/\left(p+1/2\right)$. The true inverse of
$F\left(p\right)$ is
$\mathrm{exp}\left(t/2\right)$. Two preliminary calls to the routine are made to verify that the chosen value of
ALPHAB is suitable. For these tests the single value
${\mathbf{T}}\left(1\right)=1.0$ is used. To test values of
$a$ close to
ALPHAB, the values
${\mathbf{TFAC}}=5.0$ and
${\mathbf{RELERR}}=0.01$ are chosen. To test larger
$a$, the values
${\mathbf{TFAC}}=0.8$ and
${\mathbf{RELERR}}=\text{1.0E\u22123}$ are used. Because the values of the computed inverse are similar and
${\mathbf{IFAIL}}={\mathbf{0}}$ in each case, these tests show that there is unlikely to be a singularity of
$F\left(p\right)$ in the region
$0.04\le \mathrm{Re}\left(p\right)\le 6.51$.
9.1 Program Text
Program Text (c06lafe.f90)
9.2 Program Data
Program Data (c06lafe.d)
9.3 Program Results
Program Results (c06lafe.r)