1
$\begingroup$

I have a huge problem with my code: I estimate it to take hours to run. The scheme of the code is the following (I left the steps the same, but took much simpler functions):

EX = Compile[{x, y, z}, Sin[x] Cos[y] + z];
EY = Compile[{x, y, z}, Cos[x] Sin[y] + z];

ff[x_?NumberQ, y_?NumberQ, t_?NumberQ] := EX[ x, y, t]
gg[x_?NumberQ, y_?NumberQ, t_?NumberQ] := EY[x, y, t]
ff2[x_?NumberQ, y_?NumberQ] := NIntegrate[ff[x, y, t]^2, {t, 0, 2 Pi},Method -> {Automatic, "SymbolicProcessing" -> 0}, PrecisionGoal -> 2]/(2 Pi)
gg2[x_?NumberQ, y_?NumberQ] := NIntegrate[gg[x, y, t]^2, {t, 0, 2 Pi},Method -> {Automatic, "SymbolicProcessing" -> 0}, PrecisionGoal -> 2]/(2 Pi)

Plot3D[ArcTan[Sqrt[gg2[x, y]/ff2[x, y]]], {x, -2.7, 2.7}, {y, -2.7,2.7}, PlotRange -> {0, 1}]

I really need at least X100 speedup. Maybe I have picked a wrong strategy...

What I have also tried to do is to do all the math symbolically and then give the function to the Plot3D. In this case compilation slows down because of symbolic integration, but plotting runs much faster.

I have also tried to tabulate the precompiled functions, it takes just as long to make a considerably fine table.

If more information is needed, please ask!

$\endgroup$
  • 3
    $\begingroup$ Your simpler example is perhaps too simple. It's quite possible that an effective strategy will depend on the actual code for the functions. There are many possible opportunities and pitfalls with integration. $\endgroup$ – Michael E2 Apr 23 '16 at 1:53
  • $\begingroup$ I don't really know how can I add my code here except putting it to the post. HTML makes it unreadable. It would not probably be very helpful=( Are there options on how could I share my functions in a readable format. $\endgroup$ – MsTais Apr 23 '16 at 17:09
  • $\begingroup$ Some people post long code on pastebin.com or similar. (SE sites can handle somewhat longish code if formatted as code block in Markdown properly -- it makes a scrollable window. See this for example.) $\endgroup$ – Michael E2 Apr 23 '16 at 17:26
  • 1
    $\begingroup$ Thank you Michael, I have tried to download it here pastebin.com/WjH17ckM $\endgroup$ – MsTais Apr 24 '16 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.