Group Abstract Group Abstract

Message Boards Message Boards

How can I use Manipulate with a NIntegrate defined function?

Posted 8 years ago

Hi, I'm trying to model a spiral galaxy using some density distributions and display them with a 2D density plot. The functions are integrated along a line of sight in order to reduce the 3 variables functions to 2 variables function. In order to make a rotating plot I'm trying to use Manipulate. Here it is my code, which gives me as output only a static image that doesn't rotate moving the slider. The code is this:

LogarithmicScaling[x_, min_, max_] := Log[x/min]/Log[max/min]
f[x_?NumericQ, y_?NumericQ, t_?NumericQ] := 
 NIntegrate[
  2.872416767*10^3*Exp[(-Sqrt[x^2 + y^2])/2.676]*Exp[(-Abs[z] + 1- Cos[2*(ArcTan[y/x] - t) + (2/(Tan[7*Pi/90]))*Log[Sqrt[x^2 + y^2]/4.9]])] +7.013941065*10^5*Exp[-Sqrt[x^2 + y^2 + z^2]/0.09866] + (7.321354473)/(1 + (Sqrt[x^2 + y^2 + z^2]/3.936)^2)^(5/2), {z, -Infinity, +Infinity}]

plotter[min_, max_, NumberOfTicks_] := 
 Manipulate[DensityPlot[f[x, y, t], {x, -25, 25}, {y, -25, 25}, 
   PlotRange -> Full, ColorFunctionScaling -> False, 
   ColorFunction -> (ColorData["SunsetColors"][
       LogarithmicScaling[#, min, max]] &), PlotPoints -> 50, 
   PlotLegends -> 
    BarLegend[{ColorData["SunsetColors"], {0, 1}}, 
     LegendMarkerSize -> 370, 
     Ticks -> ({LogarithmicScaling[#, min, max], 
          ScientificForm[#, 1]} & /@ (min (max/min)^
           Range[0, 1, 1/NumberOfTicks]))]], {t, 0, 100}, 
  AnimationRunning -> False, SynchronousUpdating -> False ]
plotter[10^1, 10^5, 4]

The static image which has to rotate is shown in the attachment. If I plot the function fixing t with different values, it actually rotates, but the manipulate function seems to not work at all. Any idea?

Attachments:
POSTED BY: Eliseo Pavone
5 Replies
POSTED BY: Michael Rogers
POSTED BY: Gianluca Gorni

Have you tried Compile?

POSTED BY: Gianluca Gorni
Posted 8 years ago

Thank you Gianluca, your advice has been really helpful. At the end I chose to do a table with all the plots and create an .avi file because it was still too slow with manipulate.

POSTED BY: Eliseo Pavone

For me it works if I fix the syntax error with BarLegend not having the ] in the right place. However, it takes a long time to compute. I assume it rotated eventually when I moved t, but I wasn't looking when the computation finished.

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