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.
ModuletoDynamicModule. The reason for the syntax highlighting is that one should not use ``Modulevariables insideDynamic`. Ref.: http://mathematica.stackexchange.com/a/29461/18476 – Karsten7 Oct 03 '16 at 12:13Dynamic[]should not beModulevariables, when the scope of theModulecontains 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. – Michael E2 Oct 03 '16 at 12:19αto change when the variable fov changes because fov sets the limits ofα. – Tomas Libutti Oct 03 '16 at 12:21αis reset whenλ,Δ, ore0changes, even thoughfovis unaltered? – Michael E2 Oct 03 '16 at 12:28Gridare used in the subsequent part of the code but I cant end this command with;because I need the bars to be printed when the program is executed. This is a problem because if I write another equation belowGridwithout the semicolon at the end the programs gives meNullat the output. How can I solve this? Thanks – Tomas Libutti Oct 03 '16 at 12:45alphabeing defined in the control section because there is a problem with the limits depending on the variablefovwhich is defined inside the code. It gives any value toalphanot related to te actual value offov– Tomas Libutti Oct 03 '16 at 13:04αin the previous code) whenever I try to operate with this variable I get an error and if I want to printαas output Mathematica return this symbol:α$$. Any clue? – Tomas Libutti Oct 03 '16 at 16:35