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!