I am using Manipulate
to simulate Brownian motion. I want to be able to zoom in. Thus, I want to use Dynamic
for the PlotRange
option so that this can be done quickly without recomputing the motion. It works properly without Dynamic
(except for speed), but using Dynamic
changes its operation so that the range is no longer what I ask for once I zoom in sufficiently. See this by changing the "horizontal zoom". I also have the same PlotRange
in Show. It seems I need both. No doubt I am not doing other things optimally, but this issue is a separate problem. Here is my code, first without the first Dynamic
and second with it. At the end is a smaller example. It behaves differently, but again the behavior depends on whether PlotRange has Dynamic or not. This last example contains both types of code in it. It comes in two forms, one using Show and one not.
Manipulate[
Module[{bmPath, iterate}, SeedRandom[seed];
iterate[l_List] :=
Module[{i = 1, len = Length[l], new = l},
While[i < Length[new],
new = Insert[
new, (new[[i]] + new[[i + 1]])/2 +
RandomVariate[NormalDistribution[0, .5/Sqrt[(len - 1)]]],
i + 1]; i = i + 2]; new];
bmPath = {0, RandomVariate[NormalDistribution[0, 1]]};
Do[bmPath = iterate[bmPath], {n}];
Show[ListLinePlot[bmPath, AxesLabel -> {"Time", "Location"},
DataRange -> {0, 1},
PlotRange -> {Clip[{hcenter - 2^(-zoom), hcenter + 2^(-zoom)}, {0,
1}], vcenter + {-2, 2}/2^(scale/2)}],
Plot[{Sqrt[x], -Sqrt[x]}, {x, 0, 1},
PlotStyle -> If[bound, Dotted, Opacity[0]]],
PlotRange ->
Dynamic[{Clip[{hcenter - 2^(-zoom), hcenter + 2^(-zoom)}, {0, 1}],
vcenter + {-2, 2}/2^(scale/2)}],
AxesOrigin -> Dynamic[{hcenter, vcenter}],
ImageSize -> {475, 360}]],
{{n, 10, "detail"}, 1, 40, 1, Appearance -> {"Labeled", "Open"},
AnimationRate -> rate}, {{rate, 1, "rate"}, 1, 3, 1,
Appearance -> "Labeled"}, {{bound, False,
"show sqrt bounds"}, {True, False}}, Delimiter, {{hcenter, .5,
"horizontal center"}, 0, 1, .01/2^(zoom - 1),
Appearance -> {"Labeled", "Open"},
AnimationRate -> .2/2^(zoom - 1)}, {{vcenter, 0,
"vertical center"}, -3, 3, .01/2^(scale - 1),
Appearance -> {"Labeled", "Open"},
AnimationRate -> .1/2^(scale - 1)}, Delimiter, {{zoom, 1,
"horizontal zoom"}, 1, 20, 1,
Appearance -> {"Labeled", "Open"}}, {{scale, 1,
"vertical scale"}, -2, 20, 1,
Appearance -> {"Labeled", "Open"}}, Delimiter, {{seed, 77777,
"new random case"}, 10000, 999999, 1, Appearance -> "Open",
AnimationRate -> newrate}, {{newrate, 1, "rate of new case"}, 1, 10,
1, Appearance -> "Labeled"},
ControlPlacement -> Right, SynchronousUpdating -> False]
Manipulate[
Module[{bmPath, iterate}, SeedRandom[seed];
iterate[l_List] :=
Module[{i = 1, len = Length[l], new = l},
While[i < Length[new],
new = Insert[
new, (new[[i]] + new[[i + 1]])/2 +
RandomVariate[NormalDistribution[0, .5/Sqrt[(len - 1)]]],
i + 1]; i = i + 2]; new];
bmPath = {0, RandomVariate[NormalDistribution[0, 1]]};
Do[bmPath = iterate[bmPath], {n}];
Show[ListLinePlot[bmPath, AxesLabel -> {"Time", "Location"},
DataRange -> {0, 1},
PlotRange -> Dynamic[{Clip[{hcenter - 2^(-zoom), hcenter + 2^(-zoom)}, {0,
1}], vcenter + {-2, 2}/2^(scale/2)}]],
Plot[{Sqrt[x], -Sqrt[x]}, {x, 0, 1},
PlotStyle -> If[bound, Dotted, Opacity[0]]],
PlotRange ->
Dynamic[{Clip[{hcenter - 2^(-zoom), hcenter + 2^(-zoom)}, {0, 1}],
vcenter + {-2, 2}/2^(scale/2)}],
AxesOrigin -> Dynamic[{hcenter, vcenter}],
ImageSize -> {475, 360}]],
{{n, 10, "detail"}, 1, 40, 1, Appearance -> {"Labeled", "Open"},
AnimationRate -> rate}, {{rate, 1, "rate"}, 1, 3, 1,
Appearance -> "Labeled"}, {{bound, False,
"show sqrt bounds"}, {True, False}}, Delimiter, {{hcenter, .5,
"horizontal center"}, 0, 1, .01/2^(zoom - 1),
Appearance -> {"Labeled", "Open"},
AnimationRate -> .2/2^(zoom - 1)}, {{vcenter, 0,
"vertical center"}, -3, 3, .01/2^(scale - 1),
Appearance -> {"Labeled", "Open"},
AnimationRate -> .1/2^(scale - 1)}, Delimiter, {{zoom, 1,
"horizontal zoom"}, 1, 20, 1,
Appearance -> {"Labeled", "Open"}}, {{scale, 1,
"vertical scale"}, -2, 20, 1,
Appearance -> {"Labeled", "Open"}}, Delimiter, {{seed, 77777,
"new random case"}, 10000, 999999, 1, Appearance -> "Open",
AnimationRate -> newrate}, {{newrate, 1, "rate of new case"}, 1, 10,
1, Appearance -> "Labeled"},
ControlPlacement -> Right, SynchronousUpdating -> False]
Manipulate[
Module[{bmPath}, bmPath = {0, 2, 1};
Row[{ListLinePlot[bmPath, AxesLabel -> {"Time", "Location"},
DataRange -> {0, 1},
PlotRange ->
Dynamic[{Clip[{.5 - 2^(-zoom), .5 + 2^(-zoom)}, {0, 1}], {-2,
2}}], ImageSize -> {200, 100}],
ListLinePlot[bmPath, AxesLabel -> {"Time", "Location"},
DataRange -> {0, 1},
PlotRange -> {Clip[{.5 - 2^(-zoom), .5 + 2^(-zoom)}, {0,
1}], {-2, 2}}, ImageSize -> {200, 100}]}]],
{{zoom, 1, "horizontal zoom"}, 1, 20, 1,
Appearance -> {"Labeled", "Open"}},
ControlPlacement -> Right, SynchronousUpdating -> True]
Manipulate[
Module[{bmPath}, bmPath = {0, 2, 1};
Row[{ListLinePlot[bmPath, AxesLabel -> {"Time", "Location"},
DataRange -> {0, 1},
PlotRange ->
Dynamic[{Clip[{.5 - 2^(-zoom), .5 + 2^(-zoom)}, {0, 1}], {-2,
2}}], ImageSize -> {200, 100}],
Show[ListLinePlot[bmPath, AxesLabel -> {"Time", "Location"},
DataRange -> {0, 1}],
PlotRange ->
Dynamic[{Clip[{.5 - 2^(-zoom), .5 + 2^(-zoom)}, {0, 1}], {-2,
2}}], ImageSize -> {200, 100}]}]],
{{zoom, 1, "horizontal zoom"}, 1, 20, 1,
Appearance -> {"Labeled", "Open"}},
ControlPlacement -> Right, SynchronousUpdating -> True]
Dynamic[{Clip[{.5 - 2^(-zoom), .5 + 2^(-zoom)}, {0, 1}], {-2, 2}}]
is a not a proper form for the optionPlotRange
. Further theDynamic
wrapper isn't needed. $\endgroup$