Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

As the title says, I want to control the speed when I use Manipulate. I have the following piece of code

Clear["Global`*"];
Manipulate[
V = -(M/Sqrt[b^2 + x^2 + λ*y^2 + (a + Sqrt[h^2 + z^2])^2]);
Vxx = D[V, {x, 2}];
Vyy = D[V, {y, 2}];
Vzz = D[V, {z, 2}];
ρ = 2.325/(4*π*100)*(Vxx + Vyy + Vzz);
ρxy = ρ /. {z -> 0};
ρxz = ρ /. {y -> 0};
ρyz = ρ /. {x -> 0};

M = 9500; a = 3; h = 0.15; λ = 1.1;

Syz = ContourPlot[ρyz, {y, -30, 30}, {z, -30, 30}, Contours -> 20, 
ContourStyle -> Black, PlotPoints -> 50, 
RegionFunction -> Function[{y, z}, ρyz < 0], 
PerformanceGoal :> "Speed"],
{b, 0, 10, 0.1}]

My problem is that when I evaluate this in order to see what happens when the value of b changes the contours are plotted too fast without any order. Let me be more specific, the slider corresponding to b changes very fast and at any time it shows contours for completely random values of b. What I want, is to start the "animation" and be able to see in smooth and slow motion all the situations from b=0 up up b=10 using step 0.1

Many thanks in advance.

EDIT

plots = Table[
V = -(M/Sqrt[b^2 + x^2 + λ*y^2 + (a + Sqrt[h^2 + z^2])^2]);
Vxx = D[V, {x, 2}]; Vyy = D[V, {y, 2}]; Vzz = D[V, {z, 2}];
ρ = (2.325/(4*Pi*100))*(Vxx + Vyy + Vzz);
ρxy = ρ /. {z -> 0};
ρxz = ρ /. {y -> 0};
ρyz = ρ /. {x -> 0};
M = 9500; a = 3; h = 0.15; λ = 1.1;
ContourPlot[ρyz, {y, -50, 50}, {z, -50, 50}, Contours -> 20, 
ContourStyle -> Black, PlotPoints -> 50, 
RegionFunction -> Function[{y, z}, ρyz < 0], 
PerformanceGoal :> "Speed", FrameLabel -> {"y", "z"}, 
RotateLabel -> False, 
FrameStyle -> 
 Directive[FontSize -> 17, FontFamily -> "Helvetica"], 
PlotLabel -> Row[{"b = ", b}], 
LabelStyle -> 
 Directive[FontSize -> 17, FontFamily -> "Helvetica"], 
ImageSize -> 550], {b, 0, 10, 0.1}];
share|improve this question

3 Answers 3

up vote 2 down vote accepted

Here is an example using ListAnimate as Sjoerd recommended:

plots = Table[
 V = -(M/Sqrt[b^2 + x^2 + λ*y^2 + (a + Sqrt[h^2 + z^2])^2]);
 Vxx = D[V, {x, 2}]; Vyy = D[V, {y, 2}]; Vzz = D[V, {z, 2}];
 ρ = (2.325/(4*Pi*100))*(Vxx + Vyy + Vzz);
 ρxy = ρ /. {z -> 0};
 ρxz = ρ /. {y -> 0};
 ρyz = ρ /. {x -> 0};
 M = 9500; a = 3; h = 0.15; λ = 1.1;
 ContourPlot[ρyz, {y, -30, 30}, {z, -30, 30}, Contours -> 20,
   ContourStyle -> Black, PlotPoints -> 50,
   RegionFunction -> Function[{y, z}, ρyz < 0],
   PerformanceGoal :> "Speed",
   PlotLabel -> Row[{"b = ", b}]
 ],
 {b, 0, 10, 0.1}
];

ListAnimate[plots, 10, DisplayAllSteps -> True]

Mathematica graphics

The second argument controls the display speed of the pre-rendered frames.

share|improve this answer
    
Good again! But currently you have no idea what is the value of b at every time. Is there a way to add a PlotLabel like b = i where i is the value of b? –  Vaggelis_Z Mar 31 '13 at 21:42
    
@Vaggelis_Z, Yes. I'll update my answer with that. –  Mr.Wizard Mar 31 '13 at 21:45
    
One more thing! I tried to export this as an .avi file but it is way to heavy. So, is it possible to be exported as a .gif using all the intermediate steps of b? –  Vaggelis_Z Mar 31 '13 at 21:52
    
Just Export["Animation.gif", plots] will do the job right? –  Vaggelis_Z Mar 31 '13 at 21:56
    
@Vaggelis_Z Yes, it should. If you have any problems let me know. You may also wish to search the site for other questions about GIF export. –  Mr.Wizard Mar 31 '13 at 22:00

You can change the Manipulate for Animate and add the option DisplayAllSteps->True to, well, display all steps.

If you want to have a quality animation you could change the Animate to a ListAnimate with a Table generating all the plots at a higher quality setting (PerformanceGoal :> "Quality")


Clear["Global`*"];
ListAnimate[
 V = -(M/Sqrt[b^2 + x^2 + \[Lambda]*y^2 + (a + Sqrt[h^2 + z^2])^2]);
 Table[
  Vxx = D[V, {x, 2}];
  Vyy = D[V, {y, 2}];
  Vzz = D[V, {z, 2}];
  \[Rho] = 2.325/(4*\[Pi]*100)*(Vxx + Vyy + Vzz);
  \[Rho]xy = \[Rho] /. {z -> 0};
  \[Rho]xz = \[Rho] /. {y -> 0};
  \[Rho]yz = \[Rho] /. {x -> 0};
  M = 9500; a = 3; h = 0.15; \[Lambda] = 1.1;
  Syz = ContourPlot[\[Rho]yz, {y, -30, 30}, {z, -30, 30}, 
    Contours -> 20, ContourStyle -> Black, PlotPoints -> 20, 
    RegionFunction -> Function[{y, z}, \[Rho]yz < 0], 
    PerformanceGoal :> "Speed", 
    Epilog -> 
     Inset[Graphics@Text[b, BaseStyle -> {16, Bold}], Scaled[{0.5, 0.95}]]], {b, 0, 10, 0.1}]]

enter image description here

share|improve this answer
    
Very good! However, when I use Animate how can I see at any time the exact value of b? –  Vaggelis_Z Mar 31 '13 at 21:33
    
ListAnimate seems more efficient way. Could you post a simple example on how it could be used in my case? –  Vaggelis_Z Mar 31 '13 at 21:34

Just to add a little to the other two solutions: You might want to be able to compare the function values (of ρyz) as the graphs morph. To do that , one can control the contour lines and the contour shading. I chose a logarithmic scale for the contours cntrs, but I left the contour shading linear. The colors have no intrinsic meaning, so it's a question of adjusting it to what looks good.

Clear[b];
cntrs = Union@Flatten[Transpose@{-{0., 1., 2., 5.}}.{10^Range[-5, -3]}];
plots = Module[{V, M, Vxx, Vyy, Vzz, λ, h, a, ρ, ρxy, ρxz, ρyz},
   M = 9500; a = 3; h = 0.15; λ = 1.1;
   V = -(M/
       Sqrt[b^2 + x^2 + λ*y^2 + (a + Sqrt[h^2 + z^2])^2]);
   Vxx = D[V, {x, 2}]; Vyy = D[V, {y, 2}];  Vzz = D[V, {z, 2}];
   ρ = 2.325/(4*π*100)*(Vxx + Vyy + Vzz);
   ρxy = ρ /. {z -> 0};
   ρxz = ρ /. {y -> 0};
   ρyz = ρ /. {x -> 0};
   Table[
    ContourPlot[ρyz, {y, -30, 30}, {z, -30, 30}, 
     Contours -> cntrs, ContourStyle -> Black, 
     ColorFunction -> (ColorData["DeepSeaColors"][Rescale[#, {-0.0006, 0}]] &),
     ColorFunctionScaling -> False, 
     PlotPoints -> 50, RegionFunction -> Function[{y, z}, ρyz < 0.], 
     PerformanceGoal :> "Speed", PlotRange -> {-0.1, 0.0000001}, 
     PlotLabel -> Row[{"b = ", b}]],
    {b, 0, 10, 0.1}]
   ];

Then either

ListAnimate[plots, 10]

or

Manipulate[plots[[i]], {i, 1, Length[plots], 1, AnimationRate -> 10}]

ListAnimate is better, I believe, but you did ask about Manipulate.

Animation of plots

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.