Group Abstract Group Abstract

Message Boards Message Boards

0
|
12.5K Views
|
15 Replies
|
9 Total Likes
View groups...
Share
Share this post:

Cos[ Cos[\[Theta]]] Cosh[ Sin[\[Theta]]] slow in Integrate[]

Posted 11 years ago

Why does the function in the title take over 2 minutes to Integrate?

AbsoluteTiming[ Integrate[ Cos[ Cos[[Theta]]] Cosh[ Sin[[Theta]]], {[Theta], 0, 2 Pi}]]

Mathematica 10, iMac w. OS 10.9.3

POSTED BY: Gary Palmer
15 Replies
Posted 11 years ago
POSTED BY: Gary Palmer
POSTED BY: Marco Thiel

Dear Daniel,

ok, I understand the problem, I think.

Thanks,

Marco

POSTED BY: Marco Thiel
POSTED BY: Daniel Lichtblau

One caveat: some combinations of tweaks might give a wrong result. The variant below claims pi instead of 2pi.

In[714]:= AbsoluteTiming[
 Integrate[
  Simplify@TrigToExp[Cos[Cos[Theta]] Cosh[Sin[Theta]]], {Theta, 0, 
   2 Pi}, GenerateConditions -> False]]

(* Out[714]= {0.527774, \[Pi]} *)

Also, some of the timing discrepancies can have to do caching of intermediate results.

POSTED BY: Daniel Lichtblau

Dear Daniel,

why exactly is that? Giving Pi instead of 2 Pi is kind of worse than having to wait for 3 minutes for the result...

Cheers,

M.

PS: Also, the function seems to be quite well behaved:

Plot[Simplify@TrigToExp[Cos[Cos[Theta]] Cosh[Sin[Theta]]], {Theta, 0, 2 Pi}]

enter image description here

POSTED BY: Marco Thiel

And if we finally use all of the additional tweaks that Integrate offers:

AbsoluteTiming[Integrate[Simplify@TrigToExp[Cos[Cos[Theta]] Cosh[Sin[Theta]]], {Theta, 0, 2 Pi}, PrincipalValue -> True, GenerateConditions -> False]]

we get down to a quarter of a second - on my current machine that is nearly 700 times faster than the "naive integration".

Cheers,

M.

POSTED BY: Marco Thiel

GenerateConditions->False is the setting that matters in this instance.

POSTED BY: Daniel Lichtblau

I don't understand why but even without GenerateConditions->False and just the PrincipalValue it gains considerably. Adding both has a positive effect on the calculation time on my machine.

Cheers,

M.

PS: Why is it that TrigToExp speeds the process up so much? I understand that the Exp function might speed it up, but I would have assumed that MMA does that automatically. Is there an algorithmic advantage of not doing this?

POSTED BY: Marco Thiel

Oh, I think I see what you say. The TrigToExp has no effect if the GenerateConditions->False is set. In fact not using TrigToExp is not faster:

AbsoluteTiming[Integrate[Cos[Cos[Theta]] Cosh[Sin[Theta]], {Theta, 0, 2 Pi}, PrincipalValue -> True, GenerateConditions -> False]]

is on average about 0.22 s on my machine rather than 0.27 with the TrigToExp.

Cheers,

M.

POSTED BY: Marco Thiel

Still a bit faster:

AbsoluteTiming[Integrate[Simplify@TrigToExp[Cos[Cos[Theta]] Cosh[Sin[Theta]]], {Theta, 0, 2 Pi}, PrincipalValue -> True]]

takes about a third of a second.

Cheers,

M.

POSTED BY: Marco Thiel
Posted 11 years ago

All very instructive. Thanks.

POSTED BY: Gary Palmer
POSTED BY: Marco Thiel

I see what you're saying. Maple 18 did it in 265 msec.

POSTED BY: Frank Kampas

How long did it take you to do it without Mathematica?

POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard