0
|
10526 Views
|
15 Replies
|
9 Total Likes
View groups...
Share
GROUPS:

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

Posted 9 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
15 Replies
Sort By:
Posted 9 years ago
Posted 9 years ago
 The idea of the command is to do the numerical integration, which is fast, and the ask Wolfram Alpha to guess what the closed form of the solution might be. The N from NIntegrate is therefore quite important as it instructs Mathematica to use numerical integration instead of symbolic integration. If you remove the N, Mathematica tries to symbolically integrate, which - without any additional options such as GenerateConditions->False - takes quite some time as you report in your original post. I guess that the WolframAlpha request times out after three minutes. Cheers,M.
Posted 9 years ago
 Dear Daniel,ok, I understand the problem, I think. Thanks,Marco
Posted 9 years ago
 GenerateConditions->False (an overloaded option if ever there was one) also in effect turns off or at least weakens checking for path singularities. The antiderivative has a couple of them.
Posted 9 years ago
 One caveat: some combinations of tweaks might give a wrong result. The variant below claims pi instead of 2pi. In:= AbsoluteTiming[ Integrate[ Simplify@TrigToExp[Cos[Cos[Theta]] Cosh[Sin[Theta]]], {Theta, 0, 2 Pi}, GenerateConditions -> False]] (* Out= {0.527774, \[Pi]} *) Also, some of the timing discrepancies can have to do caching of intermediate results.
Posted 9 years ago
 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}] Posted 9 years ago
 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 9 years ago
 GenerateConditions->False is the setting that matters in this instance.
Posted 9 years ago
 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 9 years ago
 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 9 years ago
 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 9 years ago
 All very instructive. Thanks.
Posted 9 years ago
 Hi,I know that this is not nice and defeats the purpose, but because numerical integration is quite fast: AbsoluteTiming[NIntegrate[Cos[Cos[Theta]] Cosh[Sin[Theta]], {Theta, 0, 2 Pi}]] finishes in 0.006338 secs. The problem is that it does not give the symbolic solution. In this case, because the result is simple this dirty trick works: AbsoluteTiming@WolframAlpha[ToString[NIntegrate[Cos[Cos[Theta]] Cosh[Sin[Theta]], {Theta, 0, 2 Pi}]], {{"PossibleClosedForm", 1}, "ComputableData"}] runs for less than 5 seconds including the request to WolframAlpha. As I said, this does not give the proper symbolic solution and does not generalise to other problems. Cheers,M.PS: Ups, I just noticed a better solution: AbsoluteTiming[Integrate[TrigToExp[Cos[Cos[Theta]] Cosh[Sin[Theta]]], {Theta, 0, 2 Pi}]] gives the symbolic result and runs slightly longer than a second.
Posted 9 years ago
 I see what you're saying. Maple 18 did it in 265 msec.
Posted 9 years ago
 How long did it take you to do it without Mathematica?