Group Abstract Group Abstract

Message Boards Message Boards

1
|
10.8K Views
|
6 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Laplace transform with time shifts and trig functions are very slow

Posted 5 years ago

Greetings all - I was working on documentation for a lab I am giving where students are allowed to use either Mathematica or...something else to compute Laplace and Inverse Laplace Transforms of signals. One of the signals has a shifted step in it. Mathematica is fine with just a shifted step but is exceedingly slow when it comes to shifted functions. Here are some timed examples:

In[444]:= LaplaceTransform[UnitStep[t]*Cos[t], t, s] // AbsoluteTiming
Out[444]= {0.174166, s/(1 + s^2)}

In[445]:= LaplaceTransform[UnitStep[t - 1]*Cos[t], t, s] // AbsoluteTiming
Out[445]= {20.627, (E^-s (s Cos[1] - Sin[1]))/(1 + s^2)}

In[446]:= LaplaceTransform[UnitStep[t]*Cos[t - 1], t, s] // AbsoluteTiming
Out[446]= {0.325415, (s Cos[1] + Sin[1])/(1 + s^2)}

As you can see, multiplying Cos by a step shifted by 1 second results in about a hundred-hold slowdown. The same thing happens with HeavisideTheta (only worse):

In[447]:= LaplaceTransform[HeavisideTheta[t - 1]*Cos[t], t, s] // AbsoluteTiming
Out[447]= {30.2814, (E^-s (s Cos[1] - Sin[1]))/(1 + s^2)}

I thought perhaps putting an explicit step function with the Cos[t-1] would help but it doesn't. Unfortunately, I can't just shift all the t values to make the steps unshifted and then re-shift the result because LaplaceTransform is doing Unilateral transforms and everything before t=0 would be lost.

I did find a bit of a workaround that seems...unsatisfactory...but In[487]:= LaplaceTransform[HeavisideTheta[t - 1]*Cos[t] // TrigToExp, t, s] // ComplexExpand // AbsoluteTiming

Out[487]= {0.135704, (E^-s s Cos[1])/(1 + s^2) - (E^-s Sin[1])/(1 + s^2)}

Oddly, Wolfram Alpha does all this quicker, though still slow. It took about three seconds to get results versus the 24 or 30 from Mathematica.

I did some searching including the site: search thing for this issue and didn't find any posts, but I apologize if this is something that's come up before and I missed the discussion of it!

6 Replies

Workaround:

Re[LaplaceTransform[UnitStep[t]*Exp[I t], t, s]] // ComplexExpand // AbsoluteTiming

(* {0.0557801, s/(1 + s^2)}*)

. enter image description here

It's seems very fast.

Regards M.I.

POSTED BY: Mariusz Iwaniuk

Nice, really nice! Tanks for sharing!

POSTED BY: Henrik Schachner

You cannot "declare" that symbol t represents a real number with Element[t, Reals]. You must feed the logical assertion to the function that needs to know it as an assumption.

Assuming[Element[t, Reals], LaplaceTransform[UnitStep[t - 1]*Cos[t], t, s]]

On my machine, the assumption appeared to improve the timing, but then I reevaluated the original, and it was faster, too, so the improvement was apparently just from Mathematica's caching mechanisms rather than the assumption.

POSTED BY: John Doty
Anonymous User
Anonymous User
Posted 5 years ago
POSTED BY: Anonymous User
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard