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
InverseLaplace.GWR
InverseLaplace.ILtPair
InverseLaplace.Talbot
InverseLaplace.TransformPair
InverseLaplace.Weeks
InverseLaplace.WeeksErr
InverseLaplace.ILT
InverseLaplace.abserr
InverseLaplace.gwr
InverseLaplace.ilt
InverseLaplace.iltpair_power
InverseLaplace.opteval
InverseLaplace.optimize
InverseLaplace.setNterms
InverseLaplace.setparameters
InverseLaplace.talbot
InverseLaplace.talbotarr
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.
InverseLaplace.Talbot
— Type.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
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.
InverseLaplace.ILT
— Function.ILT(function, Nterms=32)
This is an alias for the default Talbot()
method.
InverseLaplace.GWR
— Type.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
InverseLaplace.Weeks
— Type.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
InverseLaplace.WeeksErr
— Type.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
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.
InverseLaplace.setNterms
— Function.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
.
InverseLaplace.optimize
— Function.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.
InverseLaplace.opteval
— Function.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
.
InverseLaplace.setparameters
— Function.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.
Analzying accuracy
InverseLaplace.ILtPair
— Type.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
InverseLaplace.abserr
— Function.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
.
InverseLaplace.iltpair_power
— Function.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
InverseLaplace.TransformPair
— Type.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.
Lower-level interface
Some of the lower-level routines can be called directly, without constructing types defined in InverseLaplace
.
InverseLaplace.ilt
— Function.ilt(func::Function, t::AbstractFloat, M::Integer=32)
ilt
is an alias for the default inverse Laplace transform method talbot
.
InverseLaplace.talbot
— Function.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
This function uses the fixed Talbot method. It evaluates func
for complex arguments.
InverseLaplace.gwr
— Function.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
This function uses the Gaver-Wynn rho method. It evaluates func
only for real arguments.
InverseLaplace.talbotarr
— Function.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.
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)