Here is a simple procedure doing numerical inverse Laplace transform using Post's inversion formula,
ILT:=proc(f,s) local k,dig; if nargs>2 and type(args[-1],'posint') then dig:=args[-1] else dig:=Digits fi; proc(T) local t,d,a; d:=dig; a:=Limit(); t:=evalf(T,dig); while op(0,a)='Limit' do a:=evalf(Limit((-1)^k/k!*(k/t)^(k+1)*eval(diff(f,s$k),s=k/t),k=infinity),d); d:=2*d od; evalf(a,dig) end end:
The original version of the procedure looked much more simple,
ILT:=proc(f,s) local k; t->evalf(Limit((-1)^k/k!*(k/t)^(k+1)*eval(diff(f,s$k),s=k/t),k=infinity)) end;
but later I corrected it so that it would work for a wider class of functions. Here is a simple example,
inttrans[invlaplace](2/s^3,s,t);
ILT(2/s^3,s)(10);

It can be plotted,
plot(ILT(2/s^3,s),-1..1);

It can be also used with 3 arguments, where the 3rd argument is the number of digits. For example,
ILT(2/s^10,s)(1000000);
ILT(2/s^10,s,20)(1000000);

Still, it works only for functions that can be differentiated quite simply. It doesn't work for most of test examples in Axel Vogt's post below.
I'd like to thank Axel Vogt and Georgios Kokovidis for their comments below. Axel Vogt's program works for much wider class of functions than ILT. A good thing would be if a future version of Maple provided access to NAG Fortran library functions for inverse Laplace transform, C06LBF and C06LCF (Weeks' method) and an older procedure C06LAF (Crump's method).
______________
Alec Mihailovs
http://mihailovs.com/Alec/
Comments
Numerical Inverse Laplace Transform
Greetings. From the link above, the description of Post's formula states,
"As can be seen from the formula, the need to evaluate derivatives of arbitrarily high orders renders this formula impractical for most purposes."
With all of that said, using the Bromwich Integral might be a better method for higher orders of "s".
> # Example 1 with small value of exponent(3):
> restart:
> L(s):=2/s^3;
> ls:=exp(s*t)*L(s);
> denominator:=factor(denom(ls));
> p:=solve(denom(ls)=0,s);
> res:=px->residue(ls,s=p[px]);
> res1:=res(1);
> evalf(subs(t=10.0,res1));
The answer matches your procedure above.
> # Example 2 with larger value of exponent(5):
> restart:
> L(s):=2/s^5;
> ls:=exp(s*t)*L(s);
> denominator:=factor(denom(ls));
> p:=solve(denom(ls)=0,s);
> res:=px->residue(ls,s=p[px]);
> res1:=res(1);
> evalf(subs(t=10.0,res1));
Here we get an answer that matches what intrans(invlaplace) yields with the substitution of t=10. Because of the higher order of s, the procedure you have listed above does not return a numerical value.
Regards,
Georgios Kokovidis
P.S. Welcome back to Maple. I missed your posts. Most of what I know in Maple I learned from studying examples like yours. Thanks.
Floating values
It returns the answer if the entered value is a float,
ILT(2/s^5,s)(10.);
Thank you for mentioning that, I'll add convertion to floats.
The inverse Laplace transform is an ill-posed numerical problem, so there is no a solution that is good for all cases. Bromwich integral requires knowing the maximum real part of the poles. It also has numerical problems related to calculating of large exponentials. Is a method practical or not, is a matter of opinion. Every method has it's own boundaries.
Thank you for welcoming me back. Who knows how long that will last this time...
__________
Alec Mihailovs
http://mihailovs.com/Alec/
Stehfest algorithm
num_invLaplace_1:=proc(F,tau) # Stehfest algorithm, according to Kou #option remember; local oldDigits, w,g, result, n,nMax, r,k, t; nMax:=20; oldDigits:=Digits: Digits:=oldDigits + max(80, 2*nMax); w:= unapply( (-1)^(n-k)*k^n/k!/(n-k)!, k,n); g:= unapply( ln(2)/t*(2*k)!/k!/(k-1)!*Sum( (-1)^r*binomial(k,r)*F((k+r)*ln(2)/t) ,r=0..k), k,t): t:=evalf(tau); result:= 0; k:=1; while ( k LE nMax ) do result:= evalf(result + w(k, nMax)*g(k,t)); k := k+1; end do; return evalf[oldDigits](result); end proc; Read 'LE' as less or equal (i never understand how to input that here ...) some test functions: #F:= s -> 1 / (s + 0.5); F:= s -> 1/((s^2-1)^(1/2)); F:= s -> s^2/(s^2+2^2)^(3/2); F:= s -> 2/s^8; inttrans[invlaplace](F(s), s, T): f:=unapply(%,T); #plot( f(t), t=0..8); 2 F := s -> ---- 8 s 7 f := T -> 1/2520 T some test values: tTst:=10; num_invLaplace_1(F,tTst); #num_invLaplace(F,tTst); evalf(f(tTst)); `approximation error` = evalf(%-%%); tTst := 10 3968.2539682541 3968.2539682540 -9 approximation error = -0.1 10 The other test functions involve Bessel functions and need more steps.LE
Axel,
Thank you again.
The input here is in html, so html entities should be used for special characters, see the list of them at HTML 4.01 Entities Reference or at ASCII - ISO 8859-1 (Latin-1) Table with HTML Entity Names. In particular, less-than sign can be entered as <
__________
Alec Mihailovs
http://mihailovs.com/Alec/
Plain Text
You also have the option to switching to a plain text input format. This will allow you to include any Unicode characters you wish without needing to use special HTML characters.
To do this, click on Input Format below the entry field and choose the "Plain Text" radio butotn.
____
William Spaetzel
Marketing Engineer, Maplesoft
Whitt
HTML has a lot of advantages
Like everything, using HTML for input has some advantages and some disadvantages. The main deisadvantage is that < sign and
styleshould be corrected. From my point of view, HTML input has much more advantages than disadvantages: tags for entering 2d math, italics, bold text, underlined, html links, unordered and ordered lists, definition lists, subscripts and superscripts, inserting pictures etc. Perhaps, I would think differently if web development wasn't my second profession though.__________
Alec Mihailovs
http://mihailovs.com/Alec/
non-communication style at the www
Alec,
I can guess you mean "fire a question and forget, www will answer".
Quite common at the usenet (as it is minimalistic), but not at a
board, yes. May be some do not even recognize their un-politeness
(same as mails without greetings or magic words like "Please" or
"Thanks"). Sometimes that annoys me too. And I have to admit, that
I am already a bit infected :-( But it does not frustrate me at all
if I found an answer.
For the Blogs ... may be the originators also are a bit shy and do
not understand it as an invitation and see it as _your_ blog (me as
well a little bit).
Also want to say: fine to read and here from you again :-)
Mapleprimes vs. Usenet
Beside (some) Maplesoft people posting here (from time to time), I prefer posting here for few other reasons as well.
I like that it is moderated.
I like that posts can be edited or even deleted. For example, being in a bad mood, I can write something about 'nuclear objects', but next morning I can delete that and pretend that nobody read it.
Also, I like user pictures and Maple rating.
I am missing Edwin Clark's, Robert Israel's, and Carl Love's (in alphabetical order) posts here though, as well as other experts' mentioned on my old Maple page posts.
__________
Alec Mihailovs
http://mihailovs.com/Alec/
Stehfest algorithm, vector format
Here is the same in 'vector format', which is faster. If the function to be input is real without singularities then the procedure is converging after ~ 20 steps (but for the example where Bessels are involved the evaluations may result in complex values, dito for 1/sqrt(s-1)) and the thing becomes not very reliable (just try the last examples in a point T=12 or so). But for good situations is is fine. As a variant I played with (pre-)computing the factorials with high precision and then to continue with working precision. It was not convincing (and needs to take too much care for the number of steps), 60 - 80 digits seems to be needed at least. num_invLaplace_2:=proc(F,tau) #option remember; local oldDigits, n, r,k, t, result, Y,B,W,G; n:=80; # max of fct evaluations and summands oldDigits:=Digits: Digits:=oldDigits + max(80, 2*n); t:= evalf(tau); Y:= Vector((0+1)..(n+n), (k) -> F(k*ln(2.0)/t) ); B:= Matrix(1 .. n, 1+0 .. 1+n, (i,j) -> binomial(i,j-1) ); W:= Vector(1 .. n, (k) -> (-1)^(n-k)*k^n/k!/(n-k)! * (2*k)!/k!/(k-1)! ); G:= Vector(1 .. n, (k) -> add((-1)^r*B[k,r+1]*Y[k+r], r = 0 .. k) ); result:= ln(2.0)/t * add( evalf(W[k]*G[k]), k=1 .. n); return Re( evalf[oldDigits](result) ); end proc; Likewise one can use a recursion to get the weights (a bit faster): W:= Vector(1 .. n); W[1]:= 2*(-1)^(n-1)/(n-1)!; for k from 1 to n-1 do W[k+1] := ( 2*(2*k+1)*(k-n)*((k+1)/k)^(n-1)/k^2 ) * W[k]; end do; k:='k';a better way (i hope)
Losing interest
Axel,
You know, when a person asking a question doesn't even reply to our posts, I am losing interest to continuing a topic. That seems to happen with almost all of my blog posts. Recently - < a href="http://www.mapleprimes.com/blog/alec/matrix-algebra-over-finite-fields">Matrix Algebra over Finite Fields
, Simulation of Brownian Motion, 1d phase portrait in Classic Maple, as well as this one, Numerical Inverse Laplace Transform.__________
Alec Mihailovs
http://mihailovs.com/Alec/
Numerical Inversion of the Laplace Transform
Have you had a look at Zakian's Method of numericaly inverting Laplace transforms, quick, simple but does have its problems
Please replace this text with the link to your file.
The link can be found in the File Manager
your link is missing
Fay, if you uploaded something ... the link does not appear here ... did you?
"Power Algorithms for Inverting Laplace Transforms" by Whitt et al mentions
that approach and generalizes it
Missing upload
She didn't upload any files. It can be seen by clicking on her name and then on 'View uploaded files'.
If I didn't lose interest to that topic, I might even post the procedure that I was actually using for that :)
_________
Alec Mihailovs
http://mihailovs.com/Alec/
Numerical Inversiojn
I have on a number of tried to upload the Maple Worksheet demonstrating Zakian's method of numerically inverting the Lapalce transform but the files seem to vanish! Is there a bug in the uploading routine?
Please replace this text with the link to your file.
The link can be found in the File Manager
Numerical Inversion
If there is not a problem with the uploading mechcanism, perhaps someone can write a procedure on how to do it, as I have tried to upload this worksheet any number of times!
you proceed as follows:
File Uploading
Yep done all that, even had the tea as suggested, only problem is the files still do not appear to have uploaded!
Zakian's Method
As there appears to be a problem uploading the maple worksheet maybe this will work!
> restart:
> Zakian := proc(Fs,t)
local a,k;
if t = 0 then
error("The approximation is undefined for the value t = 0")
end if:
a[1] := 12.83767675e0 + j*1.666063445e0:
a[2] := 12.22613209e0 + j*5.012718792e0:
a[3] := 10.93430308e0 + j*8.409673116e0:
a[4] := 8.776434715e0 + j*11.92185389e0:
a[5] := 5.225453361e0 + j*15.72952905e0:
k[1] := -3.690208210e4 + j*1.969904257e5:
k[2] := 6.127702524e4 - j*9.540862551e4:
k[3] := -2.891656288e4 + j*1.816918531e4:
k[4] := 4.655361138e3 - j*1.901528642e0:
k[5] := -1.187414011e2 - j*1.413036911e2:
return(2/t*add(Re(k[i]*eval(Fs,s = a[i]/t)),i = 1..5))
end proc:
> f(t) := sin(4*t)*exp(-t);
f(t) := sin(4 t)exp(-t)
> F(s) := laplace(f(t),t,s);
4
F(s) := -------------
2
s + 2 s + 17
> plot({f(t),Zakian(F(s),t)},t = 0.001..8);
File Uploading
Yep done all that, even had the tea as suggested, only problem is the files still do not appear to have uploaded!
Here is Fay's file for the Zakian algorithm ...
.... Download 102_(Fay)ZakiansAlgorithm.mws ... and now I have some beer instead of tea :-)