I have a problem while playing with a Dynamic
Slider
inside a Manipulate
. The code looks like this:
Manipulate[
Module[{efl, swath, fov, d1, R1, R2, α},
efl = (1 10^-3) (h p)/gsd;
swath = (1 10^-3) np gsd;
fov = (1/Degree) 2 ArcTan[swath/(2 h)];
d1 = FindRoot[
1.0 - (1 10^-3) (λ h)/(
x grd) (1 + ((x p)/(λ efl))^1.35)^(1/1.35), {x,
1 10^-3}, MaxIterations -> 100][[1, 2]];
R1 = -2 (Δ efl)/((-Δ + e) - efl);
R2 = 2.0 ((-Δ + e) (R1/2.0 - Δ))/(R1/
2.0 - 2.0 Δ + e);
Grid[{{"α",
Dynamic@Slider[Dynamic[α], {-(fov/2), fov/2, fov/10},
AutoAction -> False],
Dynamic[α]}}]
],
Grid[{
{Row[{Control[{{λ, 0.1, "Wavelenght [μm]"},
Range[0.1, 1.0, 0.1]}], Spacer[40],
Control[{{h, 400, "Altitude [Km]"}, Range[400, 700, 50] }],
Spacer[40],
Control[{{gsd, 0.3, "GSD [m]"}, Range[0.3, 5.0, 0.1] }],
Spacer[40],
Control[{{p, 2, "Pixel Pitch [μm]"},
Range[2.0, 15.0, 1.0]}], Spacer[40],
Control[{{np, 2000, "\!\(\*SubscriptBox[\(N\), \(p\)]\) [U.A]"},
Range[2000, 12000, 1000] }]}], Spacer[40]},
{},
{Grid[{{"GRD",
Dynamic@Slider[
Dynamic[grd], {gsd (1 + (1 10^-3 (λ h)/(
12.0 gsd))^1.35)^(1/1.35) , 10 gsd},
AutoAction -> False], Dynamic[grd]}}]},
{},
{Row[{Control[{{Δ, -0.5, "Dist. P-S [m]"},
Range[-0.5, -0.1, 0.02]}], Spacer[40],
Control[{{e0, 0.01, "Focus Distance [m]"},
Range[0.01, 0.1, 0.01]}]}]}}], SaveDefinitions -> True]
The problem is in the definition of α. With Manipulate
I can control the basic parameter for the calculation of efl
, swath
, fov
, d1
, R1
and R2
. The limits for the Slider
which varies α depends on the variable fov
. Dont know why but Mathematica doesnt like the way I'm defining this variable and highlights in red the fov
parameter inside the Dynamic@Slider of α
. What I'm doing wrong?
Any help would be appreciated.
Module
toDynamicModule
. The reason for the syntax highlighting is that one should not use ``Module` variables insideDynamic
. Ref.: mathematica.stackexchange.com/a/29461/18476 $\endgroup$Dynamic[]
should not beModule
variables, when the scope of theModule
contains theDynamic
.Dynamic[Module[{x},f[x]]]
is OK, but notModule[{x}, Dynamic[f[x]]]
. UsingDynamicModule[]
instead as @Karsten suggests is OK, but it might not work the way you want. It will resetα
every time a control is changed. $\endgroup$α
to change when the variable fov changes because fov sets the limits ofα
. $\endgroup$α
is reset whenλ
,Δ
, ore0
changes, even thoughfov
is unaltered? $\endgroup$