# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

As of Version 12.2, numerical capabilities are built in to InverseLaplaceTransform.

Function Repository Resource:

Find the numerical approximation for the inverse Laplace transform

Contributed by:
Peter Valko (p-valko@tamu.edu)

professor emeritus of Petroleum Engineering, Texas A&M

professor emeritus of Petroleum Engineering, Texas A&M

ResourceFunction["NInverseLaplaceTransform"][ gives a numerical approximation to the inverse Laplace transform to |

Given a positive t value, the numerical approximation to the inverse Laplace transform of *expr* can be—in principle—calculated from numerically integrating , where *F*(*s*)=*expr* and *γ* is an arbitrary positive constant chosen so that the contour of integration lies to the right of all singularities in *F*(*s*). However, specialized methods are more reliable. This resource function provides an effective combination of two methods described in the references.

The *expr* must be numeric whenever symbol *s* is set to a numeric value.

Approximate numbers (numbers with decimal points) are allowed in the expression.

The *t* value must be positive, such as 2.9×10^{3} or 4×*π*^{2}.

ResourceFunction["NInverseLaplaceTransform"] returns $Failed when it cannot determine the numerical result.

ResourceFunction["NInverseLaplaceTransform"] provides the result as a machine number (about 16 significant digits).

There are two options: "Startm" and "Method" (please notice the quotation marks).

"Startm" is an integer between 5 and 15. The internal numerical inversion procedures ("FT" and "GWR") are called with 2^{m} terms so "Startm"→5 implies that 2^{5}=32 terms will be used initially.

"Method" (please notice the quotation marks) can be "FT", "GWR" or Automatic. "Method"→Automatic will use the internal procedures "FT" and "GWR" in an alternating manner, while "FT" or "GWR" will use only the corresponding internal procedure.

The default options are {"Startm"→5,"Method"→Automatic}, so ResourceFunction["NInverseLaplaceTransform"][*expr*,*s*,*t*] is equivalent to ResourceFunction["NInverseLaplaceTransform"][*expr*,*s*,*t*,{"Startm"→5,"Method"→Automatic}].

The curly braces {} can be omitted around the options.

The expression of this example has a known symbolic Laplace inverse:

In[1]:= |

Out[1]= |

We can compare the result with the answer from the symbolic evaluation:

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]= |

This expression cannot be inverted symbolically, only numerically:

In[4]:= |

Out[5]= |

The *t* can be small or large and can contain constants (like * π*):

In[6]:= |

Out[7]= |

Compare with the answer from symbolic evaluation:

In[8]:= |

Out[8]= |

In[9]:= |

Out[9]= |

The expression Log(*p**)**p* is not a Laplace transform of anything because a Laplace transform must tend to zero at *p*→∞. Nevertheless, numerical inversion returns a result that makes sense:

In[10]:= |

Out[11]= |

One way to look at *expr4* is . Note that is the Laplace transform of *f(t)*=-EulerGamma-Log[*t*], and 0.01 is the second derivative of *f(t)* at *t*=10:

In[12]:= |

Out[12]= |

In[13]:= |

Out[13]= |

In other words, numerical inversion works on a larger class of functions than inversion, but the extension is coherent with the operational rules.

The two options "Startm" and "Method" are introduced here. Consider the following Laplace transform pair:

In[14]:= |

The inverse *f5*(*t**)* is periodic-like but not exactly periodic. At reasonably small *t*-values, there is no problem:

In[15]:= |

Out[15]= |

But already at the moderate value *t*=100. we get a surprise:

In[16]:= |

Out[16]= |

The result from the NInverseLaplaceTransform function is wrong, and—what is even worse—we do not get an error message. This is what is happening the background: the internal numerical inversion procedures "GWR" (Gaver-Wynn-rho) and "FT" (Fixed-Talbot) provide the same wrong answer initially, so NInverseLaplaceTransform accepts it.

The default value of the option "Startm" is 5. In the "FT" and "GWR" internal inversion procedures, 2^{m} terms are used, so the default means that initially the number of terms is set to 2^{5}=32. For the given problem, this does not provide enough resolution.
We can try a larger "Startm":

In[17]:= |

Out[17]= |

The result is still wrong, but increasing the starting *m* again provides the correct answer:

In[18]:= |

Out[18]= |

Any larger "Startm" would do the same. Changing the default to "Startm"→7—or a larger number—would be, however, a waste of computational resources in most of the cases, so we stick with the default, "Startm"→5* .*

The other option is "Method". It can be "FT", "GWR" or Automatic. The default is Automatic, meaning that both internal procedures "FT" and "GWR" will be used in an alternating manner.

If we explicitly set the method to "FT", only that internal procedure will be called. The above problem can be solved with the default "Startm" if we specify "Method"→"GWR":

In[19]:= |

Out[19]= |

However, for significantly larger *t*-values, an elevated "Startm" is needed, regardless of the "Method" we specify. See additional remarks in the Author’s Notes.

Find the maximum value and location of the inverse Laplace transform of example 2, first graphically and then using FindMaximum:

In[20]:= |

Out[21]= |

In[22]:= |

Out[22]= |

In the next application, we need to calculate average temperature. Assume that, solving a differential equation, we’ve obtained the following analytical result for the temperature as a function of time:

In[23]:= |

Symbolic integration is unable to calculate the average temperature in the time-interval between zero and one:

In[24]:= |

Out[24]= |

Now we try numerical integration with various options:

In[25]:= |

We see that numerical integration of this function is troublesome, so we recall that the Laplace transform of *f7(t)* is:

In[26]:= |

Out[26]= |

Using the operational rule for integration, the average temperature is:

In[27]:= |

Out[27]= |

In this example, the *expr* is not a Laplace transform, and the inversion attempt fails:

In[28]:= |

Out[28]= |

For some Laplace transforms, a *t*-value that is too large (or too small) can be detrimental and will result in a failed inversion. Consider the transform of Sin(*t**)*:

In[29]:= |

Out[29]= |

A larger value of "Startm" will help, but it is better to avoid large *t*-*s* if the inverse is periodic:

In[30]:= |

Out[30]= |

The method fails in the vicinity points where the Laplace inverse, or its derivatives, have a discontinuity. In the following example at *t*=2, the third derivative of the inverse (the SawtoothWave function) has a discontinuity:

In[31]:= |

The following inverse has a discontinuity at *t*=25 and is zero for *t*<25:

In[32]:= |

Out[32]= |

Leaving out the Dirac delta component, the result of numerical inversion should agree with the simple expression:

In[33]:= |

Approaching from above with the numerical inversion, we can get quite near to the discontinuity (though with increasing computation time):

In[34]:= |

Numerical inversion works the best if the inverse transform is an analytic function.

Here, the result is a familiar number because the inverse transform is known to be Log(1+Sqrt(*t**)**)*:

In[35]:= |

Out[36]= |

In[37]:= |

Out[37]= |

In this case the Laplace transform involves the MeijerG function (a rather complicated mathematical function that is nevertheless suitable for numerical evaluation in the Wolfram Language):

In[38]:= |

Out[39]= |

We can check symbolically that the result of the numerical inversion is correct:

In[40]:= |

Out[40]= |

In[41]:= |

Out[41]= |

Here, the inverse Laplace transform happens to be the two-parameter Mittag-Leffler function:

In[42]:= |

Out[43]= |

In[44]:= |

Out[44]= |

Here, the Laplace transform expression cannot be cast easily into a "real-only" form (though it is real for positive *s**-*values):

In[45]:= |

We prepare a log-linear plot:

In[46]:= |

Out[46]= |

The log-linear plot suggests that the inverse is simply Sin(Log(*t**)**)**. *A quick check proves the assertion:

In[47]:= |

- Numerical Laplace Inversion–Wolfram Library Archive
- Numerical Inversion of Laplace Transform with Multiple Precision Using the Complex Domain–Wolfram Library Archive

- 2.0.0 – 15 July 2019
- 1.0.0 – 05 July 2019

This work is licensed under a Creative Commons Attribution 4.0 International License