InverseLaplace

InverseLaplace

Numerical inverse Laplace transform

The source repository is https://github.com/jlapeyre/InverseLaplace.jl.

This package provides three algorithms for numerically inverting Laplace transforms. InverseLaplace v0.1.0 is the last version that supports Julia v0.6. Optimization of the Weeks method is temporarily disabled for Julia v0.7.

Contents

Index

Inverse Laplace transform algorithms

Constructing these Julia types, corresponding to different numerical algorithms, returns a callable object that evaluates the inverse Laplace transform at specified points.

ft::Talbot = Talbot(func::Function, Nterms::Integer=32)

Return ft, which estimates the inverse Laplace transform of func with the fixed Talbot algorithm. ft(t) evaluates the transform at t. You may want to tune Nterms together with setprecision(BigFloat, x).

Example

Compute the inverse transform of the transform of cos at argument pi/2.

julia> ft = Talbot(s -> s / (s^2 + 1), 80);

julia> ft(pi / 2)
-3.5366510684573195e-5

Note that given Float64 input, the precision of the returned value may not be satisfactory.

julia> Float64(ft(big(pi) / 2))
2.114425886215604e-49
Note

This function uses the fixed Talbot method. It evaluates the Laplace transform function for complex arguments. The GWR method is, in general, less accurate and less stable, but does not evaluate the Laplace transform function for complex arguments.

source
InverseLaplace.ILTFunction.
ILT(function, Nterms=32)

This is an alias for the default Talbot() method.

source

ft::GWR = GWR(func::Function, Nterms::Integer=16)

Return ft, which estimates the inverse Laplace transform of func with the GWR algorithm. ft(t) evaluates the transform at t.

Example

Compute the inverse transform of the transform of cos at argument pi / 2.

julia> ft = GWR(s -> s / (s^2 + 1), 16);

julia> ft(pi / 2)
-0.001
source

w::Weeks{datatype} = Weeks(func::Function, Nterms::Integer=64, sigma=1.0, b=1.0; datatype=Float64)

Return w, which estimates the inverse Laplace transform of func with the Weeks algorithm. w(t) evaluates the transform at t. The accuracy depends on the choice of sigma and b, with the optimal choices depending on t. datatype should agree with the DataType returned by func. For convenience, datatype=Complex is equivalent to datatype=Complex{Float64}

The call to Weeks that creates w is expensive relative to evaluation via w(t).

Example

Compute the inverse transform of the transform of cos at argument pi/2.

julia> ft = Weeks(s -> s/(s^2+1), 80);

julia> ft(pi/2)
0.0
source

w::WeeksErr{datatype} = WeeksErr(func::Function, Nterms::Integer=64, sigma=1.0, b=1.0; datatype=Float64)

Return w, which estimates the inverse Laplace transform of func via the Weeks algorithm. w(t) returns a tuple containing the inverse transform at t and an error estimate. The accuracy of the inversion depends on the choice of sigma and b. See the documentation for Weeks for a description of the parameter datatype.

Example

Compute the inverse transform of the transform of cos, and an error estimate, at argument pi/2 using 80 terms.

julia> ft = WeeksErr(s -> s/(s^2+1), 80);

julia> ft(pi/2)
(0.0,3.0872097665938698e-15)

This estimate is more accurate than cos(pi/2).

julia> ft(pi/2)[1] - cos(pi/2)
-6.123233995736766e-17

julia> ft(pi/2)[1] - 0.0         # exact value
0.0

julia> ft(pi/2)[1] - cospi(1/2)  # cospi is more accurate
0.0
source

Setting parameters

The inverse Laplace tranform routines should not be treated as black boxes. They are prone to instability and can give inaccurate or wrong results. There are some parameters you can set to try to minimize these problems.

setNterms(ailt::AbstractILt, Nterms::Integer)

set the number of terms used in the inverse Laplace tranform ailt. If ailt stores internal data, it will be recomputed, so that subsequent calls ailt(t) reflect the new value of Nterms.

source
optimize(w::AbstractWeeks, t, Nterms)

Optimize the parameters of the inverse Laplace transform w at the argument t. If Nterms is ommitted, the current value of w.Nterms is retained.

The accuracy of the Weeks algorithm depends strongly on t. For some ranges of t, the accuracy is relatively insensitive to the parameters. For other values of t, even using optimized parameters results in estimates of the inverse transform that are extremely inaccurate.

optimize is expensive in CPU time and allocation, it performs nested single-parameter optimization over two parameterss.

source
opteval(w::AbstractWeeks, t, Nterms)

estimate an inverse Laplace transform at argument t using w after optimizing the parameters for t. If Nterms is omitted, then the current value of w.Nterms is used.

Use Weeks or WeeksErr to create w.

source
setparameters(w::AbstractWeeks, sigma, b, Nterms)

Set the parameters for the inverse Laplace transform object w and recompute the internal data. Subsequent calls w(t) will use these parameters. If Nterms or both Nterms and b are omitted, then their current values are retained.

source

Analzying accuracy

ILtPair(ilt::AbstractILt, ft::Function)

return an object of type ILtPair that associates ilt the inverse Laplace transform of a function with it "exact" numerical inverse ft. Calling abserr(p, t) returns the absolute error between the inverse transform and the exact value.

Example

This example compares the inversion using the Weeks algorithm of the Laplace transform of cos(t) to its exact value at t=1.0.

julia> p = ILtPair(Weeks(s -> s/(1+s^2)), cos);
julia> abserr(p, 1.0)

0.0
source
InverseLaplace.abserrFunction.
abserr(p::ILtPair, t)

Compute the absolute error between the estimated inverse Laplace transform and "exact" numerical solution contained in p at the point t. See ILtPair.

source
iltpair_power(n)

Return a TransformPair for the power function x^n. This can be used to construct an ILTPair.

julia> p  = Talbot(iltpair_power(3));

julia> Float64(abserr(p, 1)) # test Talbot method for Laplace transform of x^3, evaluated at 1
2.0820366247539812e-26
source
TransformPair{T,V}

A pair of functions for analyzing an inverse Laplace transform method. Field ft is the real-space function. Field fs is the Laplace-space function.

source

Lower-level interface

Some of the lower-level routines can be called directly, without constructing types defined in InverseLaplace.

InverseLaplace.iltFunction.
ilt(func::Function, t::AbstractFloat, M::Integer=32)

ilt is an alias for the default inverse Laplace transform method talbot.

source
InverseLaplace.talbotFunction.
talbot(func::Function, t::AbstractFloat, M::Integer=talbot_default_num_terms)

Evaluate the inverse Laplace transform of func at the point t. Use M terms in the algorithm. For typeof(t) is Float64, the default for M is 32. For BigFloat the default is 64.

If BigFloat precision is larger than default, try increasing M.

Example

julia> InverseLaplace.talbot(s -> 1 / s^3, 3)
4.50000000000153
Note

This function uses the fixed Talbot method. It evaluates func for complex arguments.

source
InverseLaplace.gwrFunction.
gwr(func::Function, t::AbstractFloat, M::Integer=gwr_default_num_terms)

Evaluate the inverse Laplace transform of func at the point t. Use M terms in the algorithm. For typeof(t) is Float64, the default for M is 16. For BigFloat the default is 64.

If BigFloat precision is larger than default, try increasing M.

Example

julia> InverseLaplace.gwr( s -> 1/s^3, 3.0)
4.499985907607361
Note

This function uses the Gaver-Wynn rho method. It evaluates func only for real arguments.

source
talbotarr(func, ta::AbstractArray, M)

Compute the inverse Laplace transform for each element in ta. Each evaluation of func(s) is used for all elements of ta. This may be faster than a broadcast application of talbot (i.e. talbot.(...) , but is in general, less accurate. talbotarr uses the "fixed" Talbot method.

source

References

J.A.C Weideman, Algorithms for Parameter Selection in the Weeks Method for Inverting the Laplace Transform, SIAM Journal on Scientific Computing, Vol. 21, pp. 111-128 (1999)

Abate, J. and Valkó, P.P., Multi-precision Laplace transform inversion International Journal for Numerical Methods in Engineering, Vol. 60 (Iss. 5-7) pp 979–993 (2004)

Valkó, P.P. and Abate, J., Comparison of Sequence Accelerators for the Gaver Method of Numerical Laplace Transform Inversion, Computers and Mathematics with Application, Vol. 48 (Iss.3-40) pp. 629-636 (2004)