What are some ways to find the numerical Laplace transform of an InterpolatingFunction? (I know that numerical Laplace transforms are rarely used but my application requires a numerical evaluation). Thanks in advance for any help -- I'm relatively new to Mathematica and would really appreciate it!
1 Answer
Taking the definition of LaplaceTransform
and using NIntegrate
is a possiblity:
(* 1d case *)
nlap[f_, s_?NumericQ] := NIntegrate[f[t] Exp[-s*t], {t, 0, ∞}]
The multi-dimensional case is a bit harder - I think this does the trick though:
(* multidimensional case *)
nlapnd[f_, s_?(VectorQ[#, NumericQ] &)] :=
With[{vars = Array[t, Length@s]},
With[{dots = vars.s, g = Apply[f, vars]},
NIntegrate[g*Exp[-dots],
Evaluate[Sequence @@ ({#, 0, ∞} & /@ vars)]]]
]
This simple test case below for f[x]:=x^2
with LaplaceTransform
2/s^3
shows the numerical one matches the analytic one, so I think my implementation is correct, at least for 1D:
f[x_] := x^2
(* make some data and the interpolation function *)
data = Table[f[x], {x, 1, 5}];
intp = Interpolation[data];
(* show that they match up *)
Show[
ListPlot[data],
Plot[f[x], {x, 0, 5}]
]
(* get the laplace transform *)
lp = LaplaceTransform[f[x], x, s]
(* result: 2/s^3 *)
(* verify the error is very small between lp transform of f[x] and the numerical
transform of the interpolation function. *)
Plot[nlap[intp, s] - lp, {s, 0, 3}]
Exp[-a t]
. This should be fast. The kernel of the integration would be `Exp[-(a +I w )t]' which is what you want. $\endgroup$