2
$\begingroup$

Although there is a ready-made code for the inverse Laplace transform in Mathematica, I want to manually write the code to define the inverse Laplace transform so I can modify it. This is my attempt:

Remove["Global`*"]
myInverseLaplaceTransform[F_, s_, t_] := (1/(2*Pi*I))* Integrate[F*Exp[s*t], {s, -I*Infinity, I*Infinity}]
myInverseLaplaceTransform[1/s, s, t] 
(* Integrate::idiv: Integral of E^(s t)/s does not converge on {(-I) ∞,I ∞}. *)

But the result appeared as follows: enter image description here

How can I solve this problem?

$\endgroup$
4
  • $\begingroup$ Check for instance Wikipedia for the proper formula and the selection of the integration contour. en.wikipedia.org/wiki/Inverse_Laplace_transform $\endgroup$ Commented Oct 12 at 21:06
  • $\begingroup$ To be more specific, using the ilfixed in the linked post i.e. ilfixed[1/s, s, t] will give you the desired result. $\endgroup$ Commented Oct 13 at 0:46
  • $\begingroup$ @xzczd Can you write the full code? Because you didn't use the function that was previously defined in the code. $\endgroup$ Commented Oct 14 at 4:12
  • $\begingroup$ @ahmed What do you mean by "you didn't use the function that was previously defined in the code"? If you mean you don't see the definition of ilfixed, then as mentioned above, the function ilfixed can be found in the linked post, please have a look. If you can't spot it, press Ctrl+F and search in the page. $\endgroup$ Commented Oct 14 at 6:01

1 Answer 1

2
$\begingroup$

I think that there are two problems.

  1. You do not Mathematica which side of the singularity to pass
  2. You do not specify that t is positive real

With the following

myInverseLaplaceTransform[F_, s_, t_, c_] := (1/(2*Pi*I))*
  Integrate[F*Exp[s*t], {s, - I*Infinity, c, I*Infinity}]

I get

Assuming[t > 0,
  myInverseLaplaceTransform[1/s, s, t, 1]]
(* 1 *)

as I would expect.

$\endgroup$
4
  • $\begingroup$ This modification performs many transformations, but when used in the following 1/(s^2 - 1) , it does not give the desired result: (sinh t) $\endgroup$ Commented Oct 14 at 4:13
  • $\begingroup$ It does for me if 1) I specify an appropriate value of c (e.g. 2, so that it is to the right of all the poles); and 2) If I apply FullSimplify to the result. $\endgroup$ Commented Oct 14 at 19:50
  • $\begingroup$ That worked, but I'm looking for something general that will work for any function because the functions affected by the Laplace transform can all be contained together at once like this ((1/s)+(1/(s+1))+(1/(s-1))+(1/(s^2 + 1))+(s/(s^2 +1))+(1/(s^2 - 1))+(s/(s^2 - 1))) , so what should I do in this case? @mikado $\endgroup$ Commented Oct 15 at 6:51
  • $\begingroup$ You can use FunctionPoles to locate the poles of your expression. You then need to choose a value greater than the largest real part of these, for example, Max[Re[First @@@ FunctionPoles[expr, s]]+1. That works for me with your example. $\endgroup$ Commented Oct 15 at 18:07

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.