Message Boards Message Boards

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

Laplace transform with time shifts and trig functions are very slow

Posted 4 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

Fantastic! Given that I am telling my students that phasors and the frequency domain are excellent for speeding things up, I love that it's complex exponentials that ended up solving this problem!

Greetings - I just checked to see if telling M that t is real helps - I am afraid that it does not:

In[1]:= Element[t, Reals]

Out[1]= t \[Element] Reals

In[2]:= LaplaceTransform[UnitStep[t - 1]*Cos[t], t, 
s] // AbsoluteTiming

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

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 4 years ago

I think, until you can justify speeding it up (by offering the source code) in the context of solving all partial differential equations, differential equations, equations, over fields and modulus - you should trust that there is a reason it does that; that it is doing something somewhat complicated (needed in general solving) your math book does not show the need of. The knowlege of some of the math people at Wolfram is quite humbling I think.

You should limit your variables to be [Element] Reals if you don't want complex surprises and you will faster processing, often.

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

Group Abstract Group Abstract